Solved

Using forward slash "/" in query

Posted on 2006-10-30
4
1,665 Views
Last Modified: 2012-08-13
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
0
Comment
Question by:saladart
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
4 Comments
 
LVL 29

Accepted Solution

by:
Nightman earned 500 total points
ID: 17838118
update [daily sales totals by account type]
set [date] =cast(mo as varchar(2)) + '/' + cast(dy as varchar(2))  + '/' + cast(YR as varchar(2))
0
 
LVL 11

Expert Comment

by:rw3admin
ID: 17838122
cause your mo, dy and YR are int
try
set [date] = cast(mo as varchar)+'/'+cast(dy as varchar)+'/'+cast(YR as varchar)
0
 

Author Comment

by:saladart
ID: 17838209
See - I knew it was something simple...

Thanks Nightman - you were first to answer...

Sean
0
 
LVL 69

Expert Comment

by:Scott Pletcher
ID: 17838214
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
0

Featured Post

Guide to Performance: Optimization & Monitoring

Nowadays, monitoring is a mixture of tools, systems, and codes—making it a very complex process. And with this complexity, comes variables for failure. Get DZone’s new Guide to Performance to learn how to proactively find these variables and solve them before a disruption occurs.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Load balancing is the method of dividing the total amount of work performed by one computer between two or more computers. Its aim is to get more work done in the same amount of time, ensuring that all the users get served faster.
Ever wondered why sometimes your SQL Server is slow or unresponsive with connections spiking up but by the time you go in, all is well? The following article will show you how to install and configure a SQL job that will send you email alerts includ…
Via a live example combined with referencing Books Online, show some of the information that can be extracted from the Catalog Views in SQL Server.
Via a live example, show how to setup several different housekeeping processes for a SQL Server.

739 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question