select * from authors where au_id in ('172-32-1176','238-95-7766','341-22-1782')
解决方案 »
- 求助SQL 存储过程 返回查询集合的困惑
- 请大侠们帮我看看下面这个语句有什么问题?
- 主键是uniqueidentifier类型,在记录集中有1,2,3。。。这样的ID
- 交叉表怎么写啊
- 恳请高工:修改一下我的“instead of代替触发器”!
- 我有一张表BB,想在表里添加一个字段DATETIME,用来记录每一条记录插入的时间
- 忘记了SQL密码怎么办,不过我可以用WIN方式登陆SQL ,有什么办法得到密码?
- Delphi+SQL Server如何在数据库中存取图象?
- 怎样将图片存入SQL Server 中,请高手帮忙
- 在PB连接后台的SQL SERVER时,向一个表写数据时老出现“无效的游标状态”提示
- 请问如何用DTS从sqlserver数据库,导出数据到DB2?
- OSQL 一点小问题.谢谢!
declare @tmp varchar(500)
set @tmp='''172-32-1176'',''238-95-7766'',''341-22-1782'''
exec('select * from authors where au_id in ('+@tmp+')')
有这样赋值的吗?一个变量好象不可以赋予多个值吧?况且set @tmp='''172-32-1176'',''238-95-7766'',''341-22-1782''应该是只给@tmp赋了一个值!请高手指教!
select * from authors where au_id in (@tmp)当成了select * from authors where au_id = '''172-32-1176'',''238-95-7766'',''341-22-1782'''
--这个句子只是示意,他本身有语法错误但是,我没有办法去证实,希望大虾指点。可以这样变通:use pubs
declare @tmp varchar(500)
set @tmp='''172-32-1176'',''238-95-7766'',''341-22-1782'''
exec('select * from authors where au_id in ('+@tmp+')')
declare @tmp varchar(500),@sql varchar(2000)
set @tmp='''172-32-1176'',''238-95-7766'',''341-22-1782'''
set @sql='select * from authors where au_id in ('+@tmp+')'
exec(@sql)