Declare @ID int,@SQL varchar(2000) Set @ID ='78330' Select 单号 From table Where id =@IDSelect @SQL = ' Select * From table1 Where 内容 like '''(Select 单号 From table Where id =@IDnpID)'''' --当然这句肯定会错,就是求这句怎么写 Print @SQL Exec(@SQL)像这样的LIKE语句怎么写,求解
单号唯一? 要是保证唯一Declare @ID int,@SQL varchar(2000) Set @ID ='78330' declare @dh varchar(10)Select top 1 @dh = 单号 From table Where id =@IDSelect @SQL = ' Select * From table1 Where 内容 like ''%'+@dh +'%''' --当然这句肯定会错,就是求这句怎么写 Print @SQL Exec(@SQL)
Declare @ID int,@SQL varchar(2000) Set @ID ='78330' Select 单号 From table Where id =@IDSelect @SQL = 'Select * From table1 Where 内容 like ''%'+(Select top 1 单号 From table Where id =@IDnpID)+'%''' --当然这句肯定会错,就是求这句怎么写 Print @SQL Exec(@SQL)
Declare @ID int,@SQL varchar(2000) Set @ID ='78330' ---------------- 错了,@id是int型,不能赋字符串呀。
看看下面代码: 好象like后面变量才行。只接放语句我也没成功use northwind Declare @ID int,@SQL varchar(2000) declare @myid varchar(5) Set @id =10248 Select top 1 @myid=customerid From orders Where orderid =@IDSelect @SQL = 'Select * From customers Where customerid like ''%'+ @myid + '%''' Print @SQL Exec(@SQL)
select t1.* from table1 t1 inner join table t on charindex(t.单号,t1.内容)>0 where t.id=@IDnpId
要是保证唯一Declare @ID int,@SQL varchar(2000)
Set @ID ='78330'
declare @dh varchar(10)Select top 1 @dh = 单号 From table Where id =@IDSelect @SQL = '
Select * From table1 Where 内容 like ''%'+@dh +'%''' --当然这句肯定会错,就是求这句怎么写
Print @SQL
Exec(@SQL)
Declare @ID int,@SQL varchar(2000)
Set @ID ='78330'
Select 单号 From table Where id =@IDSelect @SQL = 'Select * From table1 Where 内容 like ''%'+(Select top 1 单号 From table Where id =@IDnpID)+'%''' --当然这句肯定会错,就是求这句怎么写
Print @SQL
Exec(@SQL)
Set @ID ='78330'
----------------
错了,@id是int型,不能赋字符串呀。
好象like后面变量才行。只接放语句我也没成功use northwind
Declare @ID int,@SQL varchar(2000)
declare @myid varchar(5)
Set @id =10248
Select top 1 @myid=customerid From orders Where orderid =@IDSelect @SQL = 'Select * From customers Where customerid like ''%'+ @myid + '%'''
Print @SQL
Exec(@SQL)
select t1.* from table1 t1 inner join table t on charindex(t.单号,t1.内容)>0 where t.id=@IDnpId
Set @ID =78330