Click here to Skip to main content
15,892,809 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I wrote the following SQL on MSACCESS

SELECT Followup.MRN, Followup.dateentered, Followup.formname, (Followup.MRN & Format([Followup.dateentered], "yyyymmdd") & Followup.formname) AS UniqueMilestoneID
FROM Followup;

it worked fine

Now when i write this on MSSQL

SELECT Followup.MRN, Followup.dateentered, Followup.formname, (Followup.MRN & Convert([Followup.dateentered], "yyyymmdd") & Followup.formname) AS UniqueMilestoneID
FROM Followup

i get the following error

Msg 207, Level 16, State 1, Line 1
Invalid column name 'yyyymmdd'.
Msg 243, Level 16, State 1, Line 1
Type Followup.dateentered is not a defined system type.


Any Idea how to overcome the error of the "convert" function
Posted

1 solution

try

SQL
CONVERT(VARCHAR(8), Followup.dateentered), 112)


The first parameter in the Convert should be the datatype you are converting to, the second parameter is the value that you are formatting, and the last is an optional value that indicates the format to use.

See SQL Server Date Formats for a list of date format codes for sql server.
 
Share this answer
 
v3

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900