SQL Help in procedure IN statement
I ve follow procedure im SQL Server:
alter procedure sp_selectfFriends_by_cities
(
@txt_id_usuarios varchar(300)
)
as
begin
declare @sql varchar(300)
set @sql = 'select
a.int_id_usuario,
a.int_id_cidade,
b.txt_nome_cidade,
b.txt_nome_estado
from
tb_cidades_visitadas a
left join
tb_cidades
b on b.int_id_cidade = a.int_id_cidade
where int_id_usuario in (' + @txt_id_usuarios + ')'
execute(@sql)
end
Where @txt_id_usuarios is a list of users separated by commas,and the field int_id_usuario is type of BIGINT. ie:
'6663225047,1122675730,1591119304,1664930592,1685923789,100000235882380,100000292471037,100000466411115'
When i try to exe开发者_StackOverflowcute it passing that string as parameter,it returns me follow error: Incorrect syntax near '1685923789'.
But there is NO incorrect syntax.
Stranger if I remove some IDs it works. I.E:
'6663225047,1122675730,1591119304,1664930592'
Works fine!
Any ideias?
Yes
declare @sql varchar(300)
This will limit your string to 300 chars. You need to make it longer
精彩评论