Question : convert Date() to CCYYMMDD format in SQL

I have to convert Date() to CCYYMMDD format using MSSQL. i.e. if today's date yields 01/12/2001 CC date should converted respectively. I have a formula that works in MS Access in a module:
Public Function FormatCCDate(inputdate As Date)
'reformats a date in mm/dd/yyyy format to cyymmdd
    Dim lngyear As Long
    Dim lngday As Long
    Dim lngmonth As Long
    lngyear = DatePart("yyyy", inputdate)
    lngyear = lngyear - 1900
    lngday = DatePart("d", inputdate)
    lngmonth = DatePart("m", inputdate)
    FormatCCDate = (lngyear * 10000) + (lngmonth * 100) + (lngday)
End Function
This works fine in Access within a query, but I would like to do this in MS SQL 2000.

Answer : convert Date() to CCYYMMDD format in SQL

sorry
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
create Function dbo.FormatCCDate(@inputdate Datetime)    
returns varchar(15)
as    
begin    
        --reformats a date in mm/dd/yyyy format to cyymmdd    
    
        declare @lngyear bigint    
        declare @lngday bigint    
        declare @lngmonth bigint    
    
        set @lngyear = year(@inputdate)    
        set @lngyear = @lngyear - 1900    
        set @lngday = day(@inputdate)    
        set @lngmonth = month(@inputdate)    
        return( cast(((@lngyear * 10000) + (@lngmonth * 100) + (@lngday)) as varchar) + convert(varchar, @inputdate, 108) )    
end;
Random Solutions  
 
programming4us programming4us