About Me

My photo
a Dynamic and Energetic guy.....

Thursday, April 23, 2009

Play with SQL

// getting today
SET @today = CONVERT(CHAR(8), GETDATE(), 112)

//getting first day of month
SELECT DATEADD(DAY, - DATEPART(DAY, CONVERT(CHAR(8), GETDATE(), 112)) + 1, CONVERT(CHAR(8), GETDATE(), 112)) AS firstDay

//getting last day of month
SELECT DATEADD(DAY, - DATEPART(DAY, CONVERT(CHAR(8), GETDATE(), 112)), DATEADD(MONTH, 1, CONVERT(CHAR(8), GETDATE(), 112))) AS lstDay


IF EXISTS

(
SELECT
Date,IsUnblock
FROM
SOSupervisorRemarks
WHERE (Date = '11/30/2009 12:00:00 AM')
)
UPDATE SOSupervisorRemarks SET IsUnblock='False' WHERE Date = '11/30/2009 12:00:00 AM'
ELSE
INSERT INTO SOSupervisorRemarks (Date,IsUnblock) VALUES ('11/30/2009 12:00:00 AM', 'false')


//Getting Date Value from DateTime
dateadd(dd,0, datediff(dd,0,tblSLSale.ExchangeDate)) as ExchangeDate

No comments:

My Masters