Only one expression can be specified in the select list when the subquery is not introduced with(求助)
2011-09-09 17:34
911 查看
BEGIN TRAN declare @userName varchar(100) declare @userSurname varchar(100) declare @i int declare @num int declare @sqlstr nvarchar(1000) declare @error int declare @CustomId varchar(100) set @i=1 set @num=(select COUNT(*) from (select count(userid) shuliang from dbo.Users group by name,surname having count(userid)>1) as t) set @userName= (select top 1 name from (select top 1 name,surname from dbo.Users group by name,surname having count(userid)>1 order by name ASC) as t order by name desc) set @userSurname=(select top 1 surname from (select top 1 name,surname from dbo.Users group by name,surname having count(userid)>1 order by name ASC) as t order by name desc) set @sqlstr=('select * from User where name="'+CONVERT(varchar(100),@userName)+'" and surname="'+convert(varchar(100),@userSurname)+'" ') set @i=2 while @i<=@num begin set @userName= (select top 1 name from (select top (CONVERT(INT,@i)) name,surname from dbo.Users group by name,surname having count(userid)>1 order by name ASC) as t order by name desc) set @userSurname=(select top 1 surname from (select top (CONVERT(INT,@i)) name,surname from dbo.Users group by name,surname having count(userid)>1 order by name ASC) as t order by name desc) set @sqlstr=@sqlstr+('union select * from User where name="'+CONVERT(varchar(100),@userName)+'" and surname="'+convert(varchar(100),@userSurname)+'" ') print @i print @sqlstr set @i=@i+1 end exec sp_executesql @sqlstr set @error = @@error if @error <> 0 begin print '查询失败' rollback tran end
相关文章推荐
- Only one expression can be specified in the select list when the subquery is not introduced with EXI
- Only one expression can be specified in the select list when the subquery is not introduced with EXI
- An explicit value for the identity column in table can only be specified when a column list is used and IDENTITY_INSERT is ON
- An explicit value for the identity column in table 'users' can only be specified when a column list
- The function getUserId must be used with a prefix when a default namespace is not specified 解决办法
- The function getUserId must be used with a prefix when a default namespace is not specified 解决办法
- The function must be used with a prefix when a default namespace is not specified
- The function equals must be used with a prefix when a default namespace is not specified解决
- Session state can only be used when enableSessionState is set to true, either in a configuration file or in the Page directive
- The function getXX must be used with a prefix when a default namespace is not specified
- 关于The function get must be used with a prefix when a default namespace is not specified的错误
- 关于The function equals must be used with a prefix when a default namespace is not specified解决
- 关于The function equals must be used with a prefix when a default namespace is not specified解决
- The function default must be used with a prefix when a default namespace is not specified
- Hibernate异常:query specified join fetching, but the owner of the fetched association was not present in the select list
- The function equals must be used with a prefix when a default namespace is not specified
- MySQL分组查询时出现错误SELECT list is not in GROUP BY ;this is incompatible with sql_mode=only_full_group_by
- vs2005下出现“Session state can only be used when enableSessionState is set to true, either in a configuration file or in the Page directive”的解决方法
- 关于The function size must be used with a prefix when a default namespace is not specified解决
- The specified named connection is either not found in the configuration, not intended to be used with the EntityClient provider, or not valid