没看明白,可不可以描述清楚点哦
收获园豆:
5
@soarfe:
试试这个:
declare @sql nvarchar(4000)
begin
set @sql ='
select top 2 pubuser.pfs_userm.Name from pubuser.pfs_userm
except
select top 1 pubuser.pfs_userm.Name from pubuser.pfs_userm '
exec (@sql)
end;
begin
set @sql ='
select top 2 pubuser.pfs_userm.Name from pubuser.pfs_userm
except
select top 1 pubuser.pfs_userm.Name from pubuser.pfs_userm '
exec (@sql)
end;
我是這樣的
declare @sql nvarchar(4000)
declare @username nvarchar(20)
begin
set @sql ='
select top 2 pubuser.pfs_userm.Name from pubuser.pfs_userm
except
select top 1 pubuser.pfs_userm.Name from pubuser.pfs_userm '
exec (@sql)
set @sql ='
select top 2 pubuser.pfs_userm.Name from pubuser.pfs_userm
except
select top 1 pubuser.pfs_userm.Name from pubuser.pfs_userm '
exec (@sql)
如何取exec (@sql) 結果賦值給 @username
end;
end;
declare @sql nvarchar(4000)
declare @username nvarchar(20)
begin
set @sql ='select @username=Name from(
select top 2 pubuser.pfs_userm.Name from pubuser.pfs_userm
except
select top 1 pubuser.pfs_userm.Name from pubuser.pfs_userm) A '
exec sp_executesql @sql,N'@username nvarchar(20) output',@username output
select @username
end;
declare @username nvarchar(20)
begin
set @sql ='select @username=Name from(
select top 2 pubuser.pfs_userm.Name from pubuser.pfs_userm
except
select top 1 pubuser.pfs_userm.Name from pubuser.pfs_userm) A '
exec sp_executesql @sql,N'@username nvarchar(20) output',@username output
select @username
end;
@天行健 自强不息:这个可以
exec (select top 2 * from pubuser.pfs_userm
except
select top 1 * from pubuser.pfs_userm)的之為
id name
1 張三
我現在取name的值