Click here to monitor SSC
SQLServerCentral is supported by Red Gate Software Ltd.
 
Log in  ::  Register  ::  Not logged in
 
 
 
        
Home       Members    Calendar    Who's On


Add to briefcase ««12

Need help with the code Expand / Collapse
Author
Message
Posted Tuesday, June 25, 2013 9:52 AM


SSChampion

SSChampionSSChampionSSChampionSSChampionSSChampionSSChampionSSChampionSSChampionSSChampionSSChampion

Group: General Forum Members
Last Login: Today @ 2:58 PM
Points: 13,328, Visits: 12,826
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)
Post #1467253
Posted Tuesday, June 25, 2013 9:59 AM


SSCertifiable

SSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiable

Group: General Forum Members
Last Login: Today @ 12:24 AM
Points: 5,317, Visits: 12,355
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.

When you ask a question (and please do ask a question: "My T-SQL does not work" just doesn't cut it), please provide enough information for us to understand its context.

It is better to keep your mouth shut and appear stupid than to open it and remove all doubt. (Mark Twain)
Post #1467258
Posted Wednesday, June 26, 2013 1:03 PM
SSC Veteran

SSC VeteranSSC VeteranSSC VeteranSSC VeteranSSC VeteranSSC VeteranSSC VeteranSSC Veteran

Group: General Forum Members
Last Login: Wednesday, October 15, 2014 11:33 AM
Points: 202, Visits: 1,056
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.
Post #1467821
Posted Wednesday, June 26, 2013 1:13 PM


SSChampion

SSChampionSSChampionSSChampionSSChampionSSChampionSSChampionSSChampionSSChampionSSChampionSSChampion

Group: General Forum Members
Last Login: Today @ 2:58 PM
Points: 13,328, Visits: 12,826
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)
Post #1467829
Posted Wednesday, June 26, 2013 1:13 PM
SSC Veteran

SSC VeteranSSC VeteranSSC VeteranSSC VeteranSSC VeteranSSC VeteranSSC VeteranSSC Veteran

Group: General Forum Members
Last Login: Wednesday, October 15, 2014 11:33 AM
Points: 202, Visits: 1,056
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.
Post #1467830
Posted Wednesday, June 26, 2013 1:20 PM
SSC Veteran

SSC VeteranSSC VeteranSSC VeteranSSC VeteranSSC VeteranSSC VeteranSSC VeteranSSC Veteran

Group: General Forum Members
Last Login: Wednesday, October 15, 2014 11:33 AM
Points: 202, Visits: 1,056
Sean,

Thank You very much. Now I understand. Your answer is very clear.
Post #1467836
« Prev Topic | Next Topic »

Add to briefcase ««12

Permissions Expand / Collapse