February 26, 2014 at 6:58 am
Thanks for your help peple
February 26, 2014 at 7:17 am
vsamuel (2/26/2014)
I have this script below which initially could execute without problems. Now its giving me this error: "Conversion failed when converting the varchar value '099.0' to data type int."
I'm not sure but I think, '099.0' won't be recognised as an integer because of either the preceding 0 and\or the following decimal point. Int has to be a whole number.
How to post a question to get the most help http://www.sqlservercentral.com/articles/Best+Practices/61537
February 26, 2014 at 7:29 am
Perhaps you could declare a variable as DECIMAL(10,2) then set the INT column to the value in the decimal variable... a 2 step conversion.
February 26, 2014 at 7:42 am
Many thanks, I have done that and its working
February 26, 2014 at 7:49 am
You need to look up sql injection. Your code is pretty much a text book case of vulnerable to sql injection.
_______________________________________________________________
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 Modens splitter http://www.sqlservercentral.com/articles/Tally+Table/72993/.
Cross Tabs and Pivots, Part 1 – Converting Rows to Columns - http://www.sqlservercentral.com/articles/T-SQL/63681/
Cross Tabs and Pivots, Part 2 - Dynamic Cross Tabs - http://www.sqlservercentral.com/articles/Crosstab/65048/
Understanding and Using APPLY (Part 1) - http://www.sqlservercentral.com/articles/APPLY/69953/
Understanding and Using APPLY (Part 2) - http://www.sqlservercentral.com/articles/APPLY/69954/
February 26, 2014 at 7:51 am
I have a feeling too that you could make this entire thing into a few insert statements with no dynamic sql and no looping. It is so hard to read.
_______________________________________________________________
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 Modens splitter http://www.sqlservercentral.com/articles/Tally+Table/72993/.
Cross Tabs and Pivots, Part 1 – Converting Rows to Columns - http://www.sqlservercentral.com/articles/T-SQL/63681/
Cross Tabs and Pivots, Part 2 - Dynamic Cross Tabs - http://www.sqlservercentral.com/articles/Crosstab/65048/
Understanding and Using APPLY (Part 1) - http://www.sqlservercentral.com/articles/APPLY/69953/
Understanding and Using APPLY (Part 2) - http://www.sqlservercentral.com/articles/APPLY/69954/
February 26, 2014 at 8:02 am
I am pretty sure you could get rid of the dynamic sql at the very least. Isn't this this same thing for Check 1?
/* check 1 */
IF @Check1 is null
insert into Discrepancies
(
FormName,
IDNumber,
VisitDate,
ErrorDetail,
ErrVarName1,
Status
)
select @FormName,
@PatientID,
@VisitDate,
'enr_first cannot be null',
'enr_first',
'Open'
where not exists
(
select *
from Discrepancies
where FormName = @FormName
and IDNumber = @PatientID
and VisitDate = @VisitDate
and ErrorDetail = @ErrorDetail
)
It is hard to figure out exactly what your code is doing but I think the loop would be fairly easy to get rid of too.
_______________________________________________________________
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 Modens splitter http://www.sqlservercentral.com/articles/Tally+Table/72993/.
Cross Tabs and Pivots, Part 1 – Converting Rows to Columns - http://www.sqlservercentral.com/articles/T-SQL/63681/
Cross Tabs and Pivots, Part 2 - Dynamic Cross Tabs - http://www.sqlservercentral.com/articles/Crosstab/65048/
Understanding and Using APPLY (Part 1) - http://www.sqlservercentral.com/articles/APPLY/69953/
Understanding and Using APPLY (Part 2) - http://www.sqlservercentral.com/articles/APPLY/69954/
February 26, 2014 at 8:19 am
Sean Lange (2/26/2014)
It is hard to figure out exactly what your code is doing but I think the loop would be fairly easy to get rid of too.
And now it's harder because the code is gone.
February 26, 2014 at 8:27 am
Luis Cazares (2/26/2014)
Sean Lange (2/26/2014)
It is hard to figure out exactly what your code is doing but I think the loop would be fairly easy to get rid of too.And now it's harder because the code is gone.
Well I guess they "fixed" the issue and don't want to learn that the way they are doing it is far from optimal.
Too bad because this would be a great chance for the OP to learn a LOT about how to handle this type of thing.
I copied the original code before the OP removed it. I generally quote posts to avoid the code being removed. Unless the OP comes back and wants to fix the nightmarish dynamic sql I guess we will have to assume they are satisfied.
_______________________________________________________________
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 Modens splitter http://www.sqlservercentral.com/articles/Tally+Table/72993/.
Cross Tabs and Pivots, Part 1 – Converting Rows to Columns - http://www.sqlservercentral.com/articles/T-SQL/63681/
Cross Tabs and Pivots, Part 2 - Dynamic Cross Tabs - http://www.sqlservercentral.com/articles/Crosstab/65048/
Understanding and Using APPLY (Part 1) - http://www.sqlservercentral.com/articles/APPLY/69953/
Understanding and Using APPLY (Part 2) - http://www.sqlservercentral.com/articles/APPLY/69954/
Viewing 9 posts - 1 through 8 (of 8 total)
You must be logged in to reply to this topic. Login to reply