Tuesday, August 30, 2005

SQL F1


-- FOR LAST DAY OF MONTH
SET @CurrentPeriodEndDate = CONVERT( VARCHAR, Month(@EndDate)) + '/' + CONVERT( VARCHAR, @LastDay) + '/'+ CONVERT( VARCHAR, YEAR(@EndDate))

-- FOR START DAY OF MONTH
SET @CurrentPeriodBeginDate = DATEADD(mm, DATEDIFF(mm,0,@EndDate), 0)

--EXAMPLE FOR USING ORDER BY IN UNION STATEMENT
SELECT C.COMPID,C.COMPANYNAME
FROM (
SELECT COMPID, COMPANYNAME, 1 As OrderCol
FROM COMPANY WHERE CUSTID = 0
UNION ALL
SELECT COMPID, COMPANYNAME, 2
FROM COMPANY WHERE TYPE = 'New'
UNION ALL
SELECT COMPID, COMPANYNAME, 3
FROM COMPANY WHERE TYPE <> 'New'
) C
ORDER BY C.OrderCol,C.CompanyName

LinkWithin

Related Posts with Thumbnails