如何动态的插入数据select * into 表名from-CSDN论坛
1个回答
2014-12-30
展开全部
DECLARE @Airline NVARCHAR(10)
DECLARE @sql NVARCHAR(1000)
DECLARE Split_Airline CURSOR FOR
SELECT count(Airline),Airline FROM FilterTable GROUP BY Airline
ORDER BY Airline
OPEN Split_Airline
FETCH NEXT FROM Split_Airline
INTO @Airline
WHILE @@FETCH_STATUS = 0
BEGIN
--
IF OBJECTPROPERTY (object_id('@Airline'),'ISTABLE') = 1
BEGIN
--SET sql = 'SELECT field INTO V_A FROM' || tablename;
SET @sql ='SELECT * INTO '+ @Airline + ' FROM FilterTable where Airline=@Airline'
select @sql
--PREPARE s1 FROM @sql
--EXECUTE sql(@sql)
--exec sql (SELECT * INTO ''+ @Airline + '' FROM FilterTable where Airline=@Airline)
exec s1
END
FETCH NEXT FROM Split_Airline
INTO @Airline
END
CLOSE Split_Airline
DEALLOCATE Split_Airline
1,如何动态的判断已经建立的表存在
IF OBJECTPROPERTY (object_id('@Airline'),'ISTABLE') = 1
@Airline是我要动态建立的表名,这样写对吗?
2,如何select * INTO @Airline from FilterTable where Airline=@Airline
@Airline是从游标中动态获得的,要作为表名插入。
DECLARE @sql NVARCHAR(1000)
DECLARE Split_Airline CURSOR FOR
SELECT count(Airline),Airline FROM FilterTable GROUP BY Airline
ORDER BY Airline
OPEN Split_Airline
FETCH NEXT FROM Split_Airline
INTO @Airline
WHILE @@FETCH_STATUS = 0
BEGIN
--
IF OBJECTPROPERTY (object_id('@Airline'),'ISTABLE') = 1
BEGIN
--SET sql = 'SELECT field INTO V_A FROM' || tablename;
SET @sql ='SELECT * INTO '+ @Airline + ' FROM FilterTable where Airline=@Airline'
select @sql
--PREPARE s1 FROM @sql
--EXECUTE sql(@sql)
--exec sql (SELECT * INTO ''+ @Airline + '' FROM FilterTable where Airline=@Airline)
exec s1
END
FETCH NEXT FROM Split_Airline
INTO @Airline
END
CLOSE Split_Airline
DEALLOCATE Split_Airline
1,如何动态的判断已经建立的表存在
IF OBJECTPROPERTY (object_id('@Airline'),'ISTABLE') = 1
@Airline是我要动态建立的表名,这样写对吗?
2,如何select * INTO @Airline from FilterTable where Airline=@Airline
@Airline是从游标中动态获得的,要作为表名插入。
本回答被提问者和网友采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询