以下是我的存储过程的一部份。
if exists(SELECT *
FROM global_user_position_tb
where global_user_position_tb.streetid=-1 and global_user_position_tb.username=@username )
begin
/*我想保存下面这个查询为存储过程的其余部分使用怎么办*/
SELECT basicinfo_tb.globalid FROM basicinfo_tb
end/*我想在这里使用上面这个查询怎么办*/
if exists(SELECT *
FROM global_user_position_tb
where global_user_position_tb.streetid=-1 and global_user_position_tb.username=@username )
begin
/*我想保存下面这个查询为存储过程的其余部分使用怎么办*/
SELECT basicinfo_tb.globalid FROM basicinfo_tb
end/*我想在这里使用上面这个查询怎么办*/
if exists(SELECT *
FROM global_user_position_tb
where global_user_position_tb.streetid=-1 and
global_user_position_tb.username=@username)
begin
select * into #temp from (SELECT basicinfo_tb.globalid FROM basicinfo_tb )
end
-------
--select * from #temp
@username NVarChar(30) -- 用户名称
AS
/******************************************************************************
**
** 得到该用户所管辖的所有人员,当用户是直属于社区的情况下
**
*******************************************************************************/
IF EXISTS
(SELECT username, districtId, streetId, communityId
FROM global_user_position_tb
WHERE (communityId <> - 1) AND (streetId <> - 1) AND (username = @username))
BEGIN
SELECT GlobalId
INTO [#tmp]
FROM (SELECT basicinfo_tb.GlobalId
FROM basicinfo_tb INNER JOIN
global_user_position_tb ON basicinfo_tb.street = global_user_position_tb.streetId AND global_user_position_tb.username = @username) END
为什么老是提示"关键字end附近有错误"??????????????????
@username NVarChar(30) -- 用户名称
AS
/******************************************************************************
**
** 得到该用户所管辖的所有人员,当用户是直属于社区的情况下
**
*******************************************************************************/
IF EXISTS
(SELECT username, districtId, streetId, communityId
FROM global_user_position_tb
WHERE (communityId <> - 1) AND (streetId <> - 1) AND (username = @username))
BEGIN
SELECT GlobalId
INTO [#tmp]
FROM (SELECT basicinfo_tb.GlobalId
FROM basicinfo_tb INNER JOIN
global_user_position_tb ON basicinfo_tb.street = global_user_position_tb.streetId AND global_user_position_tb.username = @username) A END--加一个别名
--第一种方法:直接用存储过程返回的数据集select * from openrowset('sqloledb','Trusted_Connection=yes','exec 数据库名.dbo.存储过程名') select * from openrowset('sqloledb','Trusted_Connection=yes','exec 数据库名..存储过程名') select * from openrowset('sqloledb','localhost';'用户名';'密码','exec 数据库名..存储过程名')select * from openrowset('sqloledb','192.168.0.1';'用户名';'密码','exec 数据库名..存储过程名')-第二种方法:先创建临时表,然后再追加create table #t(...)insert into #t exec 存储过程名select * from #t
functionId, global_remainder_tb.globalid, global_remainder_tb.num, global_remainder_tb.pagename,global_remainder_tb.pagepath, global_remainder_tb.content
114 1342 1 111 NULL NULL
114 1342 1 111 NULL NULL
现在我只要得到一个,我看到distinct的使用方法,好像都是根据一个列来distinct ,而我要根据前三个列来distinct,就是说前三个可以说是我的主键,请问如何做。
insert into @t select 114,1342,1,111,NULL,NULL
union all select 114,1342,1,111,NULL,NULLselect distinct * from @t