易截截图软件、单文件、免安装、纯绿色、仅160KB

请教SQL语句select 整数 in的用法

select id from mytable where @id in (1,2,3)

错误显示是将1,2,3转换成整数时出错。

id变量时int型的,请问select in怎么用呢?
select id from mytable where @id in (1) 这样就 不会有错的,怎么会出现这种情况呢

(1,2,3)用英文的逗号

符号错了!

只是符号错了吗,如果这样就好了

引用
(1,2,3)用英文的逗号

应该是这个样子的

我用的好像就是英文符号,现在网吧,也没法知道是不是只有这个原因

等我回去看看,明天给大家答复

SQL code:
exec('select id from mytable where '+@id+' in (1,2,3)')


括号和逗号都要用英文的……

select id from mytable where id in (1,2,3)逗号用英文输入法,这是在数据库中的执行的语句

declare @id varchar(100),@sql varchar(200)
set @sql='select id from mytable where '+@id+' in (1,2,3)'
exec(@sql)
cast(@id  as varchar)

in 中多个数字, 可以用(@id1, @id2, @id3)

多谢大家的回答,我看了,我用的就是英文。错误我没说清楚——
    一,我的id是int型的,如果用set @sql='select *from mytable where '+@id+' in (1,2,3)',会提示将'select * from mytable where'转换成int时错误。
    二,如果我用作这样select *from mytable where @id in (1,2,3),则不会有错误。
   


相关问答:

jsp链接sql2000的疑问?



type Exception report


message

description The server encountered an internal error () that prevented it from fulfilling this request.

exception

org.apache.jas ......

sqlserver错误 - MS-SQL Server / 疑难问题

sqlserver2005 建立的数据库,与手持pda传输数据,最近突然出现无法传递数据的问题,pda端提示的错误时outofmemoryexception,但是pda上面的容量没有问题,
sqlserver的日子上的错误如下:
日期 2010-1-25 14:45: ......

求一SQL - MS-SQL Server / 基础类

tab1 字段:billdate,goodsid,incount,inmoney,outcount,outmoney,endprice,endcount,endamt
tab2 字段:goodsid,goodskind(商品类型)
tab3 字段:goodskind(商品类型),kindname
结果:
得到商品类型在一段时间 ......
© 2009 ej38.com All Rights Reserved. 关于E健网联系我们 | 站点地图 | 赣ICP备09004571号