saladart
asked on
Using forward slash "/" in query
I am trying to update a table using the following query:
update [daily sales totals by account type]
set [date] = mo+'/'+dy+'/'+YR
MO, DY and YR are fields in the table [daily sales totals by account type] and are all int. [date] is a varchar field.
I am getting the following error:
Server: Msg 245, Level 16, State 1, Line 1
Syntax error converting the varchar value '/' to a column of data type int.
I have tried using CAST, CONVERT, & (instead of +), single quotes, double quotes and have not been able to get this one to work. I am needing a swift kick in the butt - 'cuz I'm sure this one is something simple that I am overlooking...been working on this issue too long...
Can someone please tell me where I am going wrong?
Thanks!
Sean
update [daily sales totals by account type]
set [date] = mo+'/'+dy+'/'+YR
MO, DY and YR are fields in the table [daily sales totals by account type] and are all int. [date] is a varchar field.
I am getting the following error:
Server: Msg 245, Level 16, State 1, Line 1
Syntax error converting the varchar value '/' to a column of data type int.
I have tried using CAST, CONVERT, & (instead of +), single quotes, double quotes and have not been able to get this one to work. I am needing a swift kick in the butt - 'cuz I'm sure this one is something simple that I am overlooking...been working on this issue too long...
Can someone please tell me where I am going wrong?
Thanks!
Sean
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
See - I knew it was something simple...
Thanks Nightman - you were first to answer...
Sean
Thanks Nightman - you were first to answer...
Sean
SQL will automatically recognize YYYYMMDD as a valid format, so this is easier to do:
UPDATE [daily sales totals by account type]
SET [date] = yr * 10000 + mo * 100 + dy
UPDATE [daily sales totals by account type]
SET [date] = yr * 10000 + mo * 100 + dy
try
set [date] = cast(mo as varchar)+'/'+cast(dy as varchar)+'/'+cast(YR as varchar)