Wednesday, April 4, 2012

Scalar Functions

Here is the code we did in class for functions

--scalar functions

Use CommunityAssist 

--only eliminates duplicate rows
Select MONTH(DonationDate), DonationAmount From Donation

Select Distinct MONTH(DonationDate), DonationAmount From Donation

Select  Distinct YEAR(donationDate) as [Year] from Donation

Select Distinct DAY(DonationDate) as [Day] From Donation


Select DATEPART(YY, DonationDate) From Donation
Select DATEPART(dd, DonationDate) From Donation
Select DATEPART(mm, DonationDate) From Donation
Select DATEPART(WEEKDAY , DonationDate) From Donation
Select DATEPART(Hour, DonationDate) From Donation

Select DATEDIFF(hour, GETDATE(), '6/4/2012')

Select GETDATE()

Select Cast(DATEADD(dd, 20, GetDate()) as CHAR(11))

Select * From Donation

Select Donationkey, '$' + CAST(DonationAmount as Char(10))
 as Amount
From Donation 

Select * from Employee

Select SUBSTRING(SsNumber,1,3) + '-' +
SUBSTRING (SSNumber,4,2) + '-' +
SUBSTRING(SSNumber, 6, 4)
 From Employee

Select * From PersonAddress 

Select SUBSTRING(Street, 1, charIndex(' ',Street,1))
From PersonAddress


No comments:

Post a Comment