381
Views
2
Comments
Error executing SQL query: Incorrect syntax near the keyword 'AS'.
Question

Here is a part of SQL statement that causes issues:

FollowUpIds and FollowUpIds2 are two identical strings, only with different values inside, but for some reason the list of values FollowUpIds works well and FollowUpIds2 doesnt, that is why I put CAST (before an error was: Conversion failed when converting the nvarchar value '0,9,2' to data type int. ).

But My Query still doesnt work and I dont know how to solve this. Currently an error is this:

Please help!

Thanks, Kamila

2021-09-06 15-09-53
Dorine Boudry
 
MVP

hi Kamila,

what your doing with the cast seems to me to be bringing you further from solution rather than closer. you need a list of integers between brackets after the in, the earlier error said that it was a nvarchar and he couldn't deal with that, so the solution is not to do a cast to nvarchar.

It's hard to say without the full select and without a datamodel, but it looks to me like the FollowUpIds2 has an extra set of '' around it that shouldn't be there, which the FollowUpIds doesn't.  

So the string should be  7,5,4 and not '7,5,4'

Can you do a test in service studio, having the exact same string for both and show us the result for that (removing the cast of course)

a way to exclude anything is wrong with the sql itself, is to switch around both and test that, see what happens.

Dorine

2023-12-14 09-56-57
Yogesh Javir

Hey,

I think before use of FollowUpIds2 , you can declare new variable and set value to that newly created variable by using cast()

And use that newly created variable for further process.

Thanks

Yogesh

Community GuidelinesBe kind and respectful, give credit to the original source of content, and search for duplicates before posting.