新手求助!!存储过程union
IF OBJECT_ID ('sp_help_edm_proc') IS NOT NULLDROP PROCEDURE sp_help_edm_proc
go
CREATE PROCEDURE sp_help_edm_proc
-- Add the parameters for the stored procedure here
@city1 nvarchar(50),@city2 nvarchar(50)='',
@city3 nvarchar(50)='',@city4 nvarchar(50)='',
@city5 nvarchar(50)='',@city6 nvarchar(50)='',
@Num1 int=0,@Num2 int=0,@Num3 int=0,@Num4 int=0,@Num5 int=0
AS
SET NOCOUNT ON;
SELECT * ,
CASE
WHEN 邮箱 LIKE '%@%sohu%' THEN 'sohu'
WHEN 邮箱 LIKE '%@%yahoo%' THEN 'yahoo'
WHEN 邮箱 LIKE '%@%qq%' THEN 'qq'
WHEN 邮箱 LIKE '%@%126%' THEN '网易'
WHEN 邮箱 LIKE '%@%163%' THEN '网易'
ELSE '其他' end ISP
into #tmp01
FROM A
where 地区 in (@city1,@city2,@city3,@city4,@city5,@city6)
SELECT top (@Num1) [邮箱],[ISP],[省],[地区] into #tmp02 FROM #tmp01 where ISP='sohu' and 地区=@city1
order by newid()
union
SELECT top (@Num2) [邮箱],[ISP],[省],[地区] FROM #tmp01 where ISP='yahoo' and 地区=@city1
order by newid()
select * from #tmp02
union 附近有语法错误
[ 本帖最后由 gewei2010 于 2012-9-27 17:15 编辑 ]