Click here to monitor SSC
SQLServerCentral is supported by Redgate
 
Log in  ::  Register  ::  Not logged in
 
 
 


Need help with the code


Need help with the code

Author
Message
Sean Lange
Sean Lange
SSCoach
SSCoach (16K reputation)SSCoach (16K reputation)SSCoach (16K reputation)SSCoach (16K reputation)SSCoach (16K reputation)SSCoach (16K reputation)SSCoach (16K reputation)SSCoach (16K reputation)

Group: General Forum Members
Points: 16626 Visits: 17024
sql2k8 (6/25/2013)
Hi ,

Even without making changes like the one you have mentioned above the Job is running successfully.

If i assume Test_Code column is a culprit in the table Table_Test1 how is the job running now successfully.

Without making the above mentioned changes it should fail right. But it is not that case.

If the Job is running successfully now how can we ask the user to modify the code in the stored procedure.

Thank You,


It failed because of the implicit datatype conversion from varchar to int.

This is simple to demonstrate.


create table #Table_Test1
(
Test_Code varchar(10)
)

insert #Table_Test1
select '2314K'



The above is a simple example of your table. The insert part of your proc would have easily inserted the data. The problem is when you update it.


update #Table_Test1 set Test_Code=1001 where Test_Code=1000



That will fail because it tries to convert all values in the table to an int because of datatype precedence. Using varchar in your update will allow to not fail.


update #Table_Test1 set Test_Code='1001' where Test_Code='1000'



_______________________________________________________________

Need help? Help us help you.

Read the article at http://www.sqlservercentral.com/articles/Best+Practices/61537/ for best practices on asking questions.

Need to split a string? Try Jeff Moden's splitter.

Cross Tabs and Pivots, Part 1 – Converting Rows to Columns
Cross Tabs and Pivots, Part 2 - Dynamic Cross Tabs
Understanding and Using APPLY (Part 1)
Understanding and Using APPLY (Part 2)
Phil Parkin
Phil Parkin
SSCrazy Eights
SSCrazy Eights (8.4K reputation)SSCrazy Eights (8.4K reputation)SSCrazy Eights (8.4K reputation)SSCrazy Eights (8.4K reputation)SSCrazy Eights (8.4K reputation)SSCrazy Eights (8.4K reputation)SSCrazy Eights (8.4K reputation)SSCrazy Eights (8.4K reputation)

Group: General Forum Members
Points: 8381 Visits: 19502
sql2k8 (6/25/2013)
I will change the code like what you had said but when it was having issues with the Test_Code Column in the Table_Test1 . It should throw an error message like it cannot convert 1000 to 1001 but why was it throwing an error message like the one mentioned below.

Conversion failed when converting the varchar value '2314K' to data type int. [SQLSTATE 22018] (Error 245).


Because you used this

update Table_Test1 set Test_Code=1001 where Test_Code=1000

instead of this

update Table_Test1 set Test_Code='1001' where Test_Code='1000'

Your version forces SQL Server to attempt to convert the column to an INT in order to compare it with 1000. Version 2 uses the literal text.


Help us to help you. For better, quicker and more-focused answers to your questions, consider following the advice in this link.

If the answer to your question can be found with a brief Google search, please perform the search yourself, rather than expecting one of the SSC members to do it for you.

Please surround any code or links you post with the appropriate IFCode formatting tags. It helps readability a lot.
sql2k8
sql2k8
SSC Veteran
SSC Veteran (211 reputation)SSC Veteran (211 reputation)SSC Veteran (211 reputation)SSC Veteran (211 reputation)SSC Veteran (211 reputation)SSC Veteran (211 reputation)SSC Veteran (211 reputation)SSC Veteran (211 reputation)

Group: General Forum Members
Points: 211 Visits: 1115
Hi ,

After the data named 2314K was removed from the table the Job was working fine.
I changed the code from
update Table_Test1 set Test_Code=1001 where Test_Code=1000
update Table_Test1 set Test_Code='1001' where Test_Code='1000'
The Job is working after I had changed the Code also.

Thank You very much for helping me.
Sean Lange
Sean Lange
SSCoach
SSCoach (16K reputation)SSCoach (16K reputation)SSCoach (16K reputation)SSCoach (16K reputation)SSCoach (16K reputation)SSCoach (16K reputation)SSCoach (16K reputation)SSCoach (16K reputation)

Group: General Forum Members
Points: 16626 Visits: 17024
Glad you got it working. The important is, do you understand why changing the code will work?

_______________________________________________________________

Need help? Help us help you.

Read the article at http://www.sqlservercentral.com/articles/Best+Practices/61537/ for best practices on asking questions.

Need to split a string? Try Jeff Moden's splitter.

Cross Tabs and Pivots, Part 1 – Converting Rows to Columns
Cross Tabs and Pivots, Part 2 - Dynamic Cross Tabs
Understanding and Using APPLY (Part 1)
Understanding and Using APPLY (Part 2)
sql2k8
sql2k8
SSC Veteran
SSC Veteran (211 reputation)SSC Veteran (211 reputation)SSC Veteran (211 reputation)SSC Veteran (211 reputation)SSC Veteran (211 reputation)SSC Veteran (211 reputation)SSC Veteran (211 reputation)SSC Veteran (211 reputation)

Group: General Forum Members
Points: 211 Visits: 1115
Hi ,

After the data named 2314K was removed from the table the Job was working fine.
I changed the code from
update Table_Test1 set Test_Code=1001 where Test_Code=1000
update Table_Test1 set Test_Code='1001' where Test_Code='1000'
The Job is working after I had changed the Code also.

Thank You very much for helping me.
sql2k8
sql2k8
SSC Veteran
SSC Veteran (211 reputation)SSC Veteran (211 reputation)SSC Veteran (211 reputation)SSC Veteran (211 reputation)SSC Veteran (211 reputation)SSC Veteran (211 reputation)SSC Veteran (211 reputation)SSC Veteran (211 reputation)

Group: General Forum Members
Points: 211 Visits: 1115
Sean,

Thank You very much. Now I understand. Your answer is very clear.
Go


Permissions

You can't post new topics.
You can't post topic replies.
You can't post new polls.
You can't post replies to polls.
You can't edit your own topics.
You can't delete your own topics.
You can't edit other topics.
You can't delete other topics.
You can't edit your own posts.
You can't edit other posts.
You can't delete your own posts.
You can't delete other posts.
You can't post events.
You can't edit your own events.
You can't edit other events.
You can't delete your own events.
You can't delete other events.
You can't send private messages.
You can't send emails.
You can read topics.
You can't vote in polls.
You can't upload attachments.
You can download attachments.
You can't post HTML code.
You can't edit HTML code.
You can't post IFCode.
You can't post JavaScript.
You can post emoticons.
You can't post or upload images.

Select a forum

































































































































































SQLServerCentral


Search