SQL帮助语句中的过程

时间:2021-09-01 02:03:58

I ve follow procedure im SQL Server:

我遵循的程序是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:

@txt_id_usuarios是由逗号分隔的用户列表,而int_id_usuario字段是BIGINT的类型。即:

'6663225047,1122675730,1591119304,1664930592,1685923789,100000235882380,100000292471037,100000466411115'

When i try to execute it passing that string as parameter,it returns me follow error: Incorrect syntax near '1685923789'.

当我试图执行它并将该字符串作为参数传递时,它会返回我follow error:在'1685923789'附近的不正确语法。

But there is NO incorrect syntax.

但是没有不正确的语法。

Stranger if I remove some IDs it works. I.E:

陌生人,如果我删除了一些id,它就可以工作了。即:

'6663225047,1122675730,1591119304,1664930592'

Works fine!

没问题!

Any ideias?

的念头吗?

1 个解决方案

#1


4  

Yes

是的

declare @sql varchar(300)

声明@sql varchar(300)

This will limit your string to 300 chars. You need to make it longer

这将限制您的字符串为300字符。你需要让它变长

#1


4  

Yes

是的

declare @sql varchar(300)

声明@sql varchar(300)

This will limit your string to 300 chars. You need to make it longer

这将限制您的字符串为300字符。你需要让它变长