如何动态的插入数据select * into 表名from-CSDN论坛
1个回答
展开全部
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是从游标中动态获得的,要作为表名插入。
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询
广告 您可能关注的内容 |