Posts
460
Comments
8183
Trackbacks
0
Eine Tabelle in eine temporäre Tabelle kopieren

Es gibt mindestens 2 Wege eine Tabelle in eine temporäre Tabelle zu kopieren:

einfacher Weg: 

DECLARE @tabelle nvarchar(100)
DECLARE @sql nvarchar(1000)

set @tabelle = "TabellenName"

set @sql = 'select * into ##temp from ' + @tabelle 
exec(@sql) 

   

umständlicher Weg: 

-- eine leere temporäre Tabelle anlegen
if object_id(N'tempdb..#temp') is not null
begin
   drop table #temp
end

create table #temp(id int)  

DECLARE TabellenFelder CURSOR FOR 
select  column_name, data_type, character_maximum_length,is_nullable 
from    information_schema.columns
where   table_name = @Tabelle
order   by ordinal_position

OPEN TabellenFelder 

FETCH NEXT FROM TabellenFelder INTO @column_name, @data_type, @character_maximum_length, @is_nullable 

WHILE @@FETCH_STATUS =
      BEGIN 
            --neue Spalte hinzufügen 
            set @sql = 'alter table #temp add ' + @column_name + ' ' 
            set @sql = @sql + @data_type 
            if @data_type ='nvarchar'  
            set @sql = @sql + '(' + @character_maximum_length +')' 
            exec(@sql)

            FETCH NEXT FROM TabellenFelder INTO @column_name, @data_type, @character_maximum_length, @is_nullable  
      END

CLOSE TabellenFelder
DEALLOCATE TabellenFelder

--die erste Spalte wieder löschen
set @sql = 'alter table #temp drop column id'
exec(@sql)

-- jetzt die Tabelle in die temporäre Tabelle kopieren
set @sql = 'insert into #temp select * from ' + @Tabelle
exec(@sql) 

posted on Wednesday, May 11, 2011 11:57 AM Print
Comments
Gravatar
# re: Eine Tabelle in eine temporäre Tabelle kopieren
brad
2/18/2016 7:57 PM
Drawing a table through program needs to have ground preparation of giving a note of how many columns and rows it does exist according to essay writing services. Here i am able to see a different program on copying it to another. All it needs a copy command i guess.
Gravatar
# MSBSHSE SSC Results
SHAWN
12/22/2016 6:08 AM
Check Out Maharashtra Board SSC Result 2017.
MSBSHSE SSC Results
Gravatar
# re: Eine Tabelle in eine temporäre Tabelle kopieren
Bob
2/8/2017 5:07 AM
It’s a great pleasure to know about the recent graduation ceremony at Unity High School. In the last academic year ending 110 students were gone out from Unity High School. Keep sharing more posts on this blog! ipad 2 wholesale
Gravatar
# http://globalcolours.com/craig-tracy-using-all-global-colours-body-art-products/
firestarter
3/24/2017 10:56 AM
InstaFire is a safe and simple fire starter using wood pellets, parafin wax and volcanic rock that produces a 15 minute burn time and 30 year shelf life.
Gravatar
# maharashtra hsc 12th result 2017
Maharashtra Board 10th result 20
4/6/2017 7:16 AM
Thanks for Information about this article.
Maharashtra SSC Result 2017
Maharashtra HSC Result 2017
AP Manabadi SSC Result 2017
AP Manabadi Inter results 2017
UP Board 10th Result 2017 Ajmer
Rajasthan board 10th result 2017
Bihar board 10th Result 2017

Very good article indeed.
Gravatar
# Nice Style
Nancy
5/9/2017 1:23 AM
Programming and development code trend is being increased everywhere, even many companies desire to hear that the person who has ability to make any form by the help of coding or website pages and numerous person prefer to get higher education, but they cannot proceed cause of the degree in their faculty, but now they have a better chance to enroll at:
http://www.degreeforlifeexperience.com/non-fake/ and get a degree form online in their desired field what they want.
Gravatar
# re: Eine Tabelle in eine temporäre Tabelle kopieren
tet.guru
5/29/2017 9:07 AM
awesome post and good information shared, tet 2017 details in full


tet.guru
Gravatar
# best smartphones under 20000
best smartphones under 20000
6/7/2017 9:17 AM
GQ India lists down the best mobile phones and smartphones under Rs. 20000. Check out our picks and get the best smartphone now.
Gravatar
# re: Eine Tabelle in eine temporäre Tabelle kopieren
iOS 11 Beta
6/8/2017 11:51 AM
iOS 11 could do well with a serious Siri upgrade. A sports update integration, as is rumored, will also be a welcome addition.
Gravatar
# tutu app pokemon go
tutu app pokemon go
6/20/2017 1:47 PM
tutu app pokemon go Tutu app is an app store same as google play store but extends the limits more than google play store by providing all apps for free

Post Comment

Title *
Name *
Email
Url
Comment *  
Please add 3 and 4 and type the answer here: