Wednesday, January 11, 2012

SQL Functions

--concatination

Select (Lastname + ', ' + firstname) as [Person Name]
From Person

-- Operators
Select DonationAmount, DonationAmount * .85 as [Charity]
From Donation

Select * From Donation
Select YEAR(DonationDate) as [Year] From Donation
Select MONTH(DonationDate) as [Month] from Donation
Select  Distinct Day(DonationDate) as [Day] from Donation


Select DATEPART(MM,DonationDate) From Donation
Select DatePart(hh,DonationDate) as [Month] from Donation

Select DATEDIFF(DD,'12/31/2011', GETDATE())
Select DateAdd(YY, 5, GETDATE())

Select * from PersonAddress

Select CHARINDEX(Street, ' ') From PersonAddress


Select SUBSTRING(Street, 1, 10) 
From PersonAddress

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

Select * From Donation
Select '$' +CAST( DonationAmount as Varchar) as Amount from Donation

Select '(' + SUBSTRING(ContactInfo, 1,3) + ')' 
From PersonContact 
Where ContactTypeKey !=6

Select '$' +CAST(( DonationAmount * .85) as Varchar) as CharityAmount from Donation



No comments:

Post a Comment