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 |
|
steven.liberman1
Starting Member
15 Posts |
Posted - 2011-03-08 : 11:03:16
|
| source database: version500target database: version5_salessource version500..template_grouptarget version5_sales..template_groupselect * from version500..slxhrscreentemplates where template_group in ('ADMIN','Manager','Payroll','HR')select * from version5_sales..slxhrscreentemplates where template_group in ('ADMIN','Corp Benefits','Data Proc','Smatlinx')1. Source DB2. Target DB3. Source template group name4. Target template group name All these would be varchar(50) So what you need to do is the following: 1. From the source DB read the template content for each template name where template_group = source template group name2. Update template content in the target DB for the target group name corresponding to the template name which you read in the above loop Now what you need here is no hardcoding of database name or group name but you will have to write dynamic sql statements like - declare @sql varchar(max) set @sql = 'select * from ' + @sourceDB + '..slxhrscreentemplate where group_name = ''' + @sourceGroup + ''' and execute this @sql by- exec @sql This will give you all template rows for the source set.Now similar way you can write dynamic sql statements for what you need to do and execute them to get resultset and also update statements in a similar way.this is what I have so far:create procedure WEB_HR_ScreenTemplateUpdate {@version500 varchar(50)@version5_sales varchar(50)@version500..slxhrscreentemplates.template_group varchar(50)@version5_sales..slxhrscreentemplates.template_group varchar(50)}as-- select * from version500..slxhrscreentemplates where template_group in ('ADMIN','Manager','Payroll','HR')-- select * from version5_sales..slxhrscreentemplates where template_group in ('ADMIN','Corp Benefits','Data Proc','Smatlinx') Begin set @sql = 1; declare @sql varchar(max) set @sql = 'select * from ' + @version500 + '..slxhrscreentemplate where template_group = '(ADMIN, Manager , Payroll, HR)' + @version500..slxhrscreentemplates.template_group + ''' EndGo |
|
|
pk_bohra
Master Smack Fu Yak Hacker
1182 Posts |
Posted - 2011-03-08 : 11:47:13
|
| Are you getting any error or you have posted the script here for your future reference ? |
 |
|
|
steven.liberman1
Starting Member
15 Posts |
Posted - 2011-03-08 : 17:18:16
|
| Basically I have to write a stored procedure using dynamic sqltoupdate the slxhrscreentemplates table in version5_saleswith the information from theslxhrscreentemplates in version500I have 4 parameters:1. source Database = version5002. target Database = version5_sales3. source group = template_group4. target group = template _groupSo I have to insert this queryselect * from version500..slxhrscreentemplates where template_group in ('ADMIN','Manager','Payroll','HR')intoselect * from version5_sales..slxhrscreentemplates where template_group in ('ADMIN','Corp Benefits','Data Proc','Smatlinx')remember template_content is XML, so I have to preserve the XMLI have to pass all the parameters and use the @sql string. |
 |
|
|
visakh16
Very Important crosS Applying yaK Herder
52326 Posts |
Posted - 2011-03-09 : 10:56:45
|
| why you want to go for dynamic query? why does your objects change at runtime?------------------------------------------------------------------------------------------------------SQL Server MVPhttp://visakhm.blogspot.com/ |
 |
|
|
steven.liberman1
Starting Member
15 Posts |
Posted - 2011-03-10 : 11:40:34
|
| That was the instruction I received at the office, so I need a dynamic query. |
 |
|
|
|
|
|
|
|