Wednesday, March 28, 2012

help for T-SQL code generator for DataMart

I replicated a table from DW to DM

but i filtered the table by month.

now i have several tables with the same schema on the datamart

the table has five keys. what i want to do is to write a

sqlwizard code that will automatically write an update statement from the replicated

table. What the wizard will do is read the fields of the DM table then identify the keys and

generate the source code for update.

lets name the proc sqlwiz

exec sqlwiz (DMtable1,dwtable1)

the sp should return the desired update statement like this

update dmtable1 set DM.nonkeyfield1= dw.nonkeyfield1,

DM.nonkeyfield2= dw.nonkeyfield2,

DM.nonkeyfield3= dw.nonkeyfield3

from dwtable1 dw where

dm.keyfield1=dw.keyfield1 and

dm.keyfield2=dw.keyfield2

pls use any of the northwind table with composite pk.

my DM is sql2k5.

the sp can also be used for generating update codes for vb.net

thanks,

joey

1. You will need to use Dynamic SQL
2. Make use of INFORMATION_SCHEMA.COLUMNS

No comments:

Post a Comment