Please start any new threads on our new
site at https://forums.sqlteam.com. We've got lots of great SQL Server
experts to answer whatever question you can come up with.
| Author |
Topic |
|
sqlpal2007
Posting Yak Master
200 Posts |
Posted - 2008-05-27 : 15:31:44
|
| Hello All,I have to create dynamic insert statements for the table. For example there are DevTableA and ProdTableA tables. I worte a SQL to get the new records added in the DevTableA but are not there in ProdTableA. The result gives me a list of rows. These tables have a column 'LanguageID' and 'LText'The compare result has records only for LanguageID = 0. One I see the compare result. I am suppose to create insert statements for LanguageID = 1,2,5 and 6 and update the Ltext for those languages. The Ltext for other languages is in spreadsheet.Can anyone advice me how to create the insert statements from the comapre result and add 4 more insert statements for LanguageID = 1,2,5 and 6 with their respective Ltext.So far I thought I can create #table. Looks like I need more than 1 # table.Thanks in advance-S |
|
|
visakh16
Very Important crosS Applying yaK Herder
52326 Posts |
Posted - 2008-05-28 : 01:31:12
|
| Compare Result? Whats that? If your attempt is to insert the new records to ProdTable then isnt it enough to use Export/Import wizard to import the records from DevTable to an intermediate staging table in ProdServer and then compare it with ProdTable? What will be frequency at which you want the comparison to happen? If its a one time thing, i think you can use Export/Import. |
 |
|
|
sqlpal2007
Posting Yak Master
200 Posts |
Posted - 2008-05-28 : 11:45:42
|
| I have to compare the data between development table and prod production table where LanguageID = 0. Insert only the missing rows in prod table from dev table. But It is not just the INSERT. I have to insert four more rows for each insert row found. These inserts will be for LanguageID 1,2,5,6. We have respective Ltext for these 1,2,5,6 LanguageIDs in excel spreadsheet. I have to insert these rows with the Ltext and LanguageID.For example:If the compare result had the following rowLanguageID LText0 Are you sure?I have to insert four rows for this insert + above insertLanguageID LText1 aaaaaa(German)2 bbbbbb(France)...There is a excel spreadsheetEnglish German FranceAre you sure aaaaaa bbbbbbTeh Ltext column will be coming from the spreadsheet |
 |
|
|
visakh16
Very Important crosS Applying yaK Herder
52326 Posts |
Posted - 2008-05-28 : 12:28:47
|
quote: Originally posted by sqlpal2007 I have to compare the data between development table and prod production table where LanguageID = 0. Insert only the missing rows in prod table from dev table. But It is not just the INSERT. I have to insert four more rows for each insert row found. These inserts will be for LanguageID 1,2,5,6. We have respective Ltext for these 1,2,5,6 LanguageIDs in excel spreadsheet. I have to insert these rows with the Ltext and LanguageID.For example:If the compare result had the following rowLanguageID LText0 Are you sure?I have to insert four rows for this insert + above insertLanguageID LText1 aaaaaa(German)2 bbbbbb(France)...There is a excel spreadsheetEnglish German FranceAre you sure aaaaaa bbbbbbTeh Ltext column will be coming from the spreadsheet
You could use SSIS for this task. Using SSIS move the data from development table and excel spreadsheet to two staging tables on production. Then call a procedure to compare the first staging table and production table like this and insert extra records.It will be like this:-CREATE PROC DataInsertASBEGINDECLARE @Temp TABLE(TextField varchar(2000))INSERT INTO ProdTableAOUTPUT INSERTED.LText INTO @TempSELECT d.LanguageID,d.LTextFROM DevTableA_Staging d (staging table with data from dev server)LEFT JOIN ProdTableA pON p.PK=d.PKWHERE p.PK IS NULLAND d.LanguageID=0INSERT INTO ProdTableASELECT 1, GermanFROM Excel_Staging eINNER JOIN @Temp tON e.English=t.TextFieldUNION ALLSELECT 2, FranceFROM Excel_Staging eINNER JOIN @Temp tON e.English=t.TextFieldUNION ALL...ENDGO |
 |
|
|
sqlpal2007
Posting Yak Master
200 Posts |
Posted - 2008-05-28 : 13:27:37
|
| Thanks Visakh16. I will try your suggestion |
 |
|
|
|
|
|
|
|