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-02-28 : 10:39:09
|
| select template_id, template_name, template_content, template_group, template_section,delete_ind, applicationfrom version5_ABCM..slxHRScreenTemplateswhere template_group = 'ADMIN' or template_group = 'Corp Benefits' or template_group = 'Data Proc' or template_group = 'Smartlinx'select template_id, template_name, template_content, template_group, template_section,delete_ind, applicationfrom version500..slxHRScreenTemplateswhere template_group = 'ADMIN' or template_group = 'Mgr' or template_group = 'Payroll' or template_group = 'HR'How would I replace the information in version500 with the information from version5_ABCM and write a stored procedure in dynamic SQL? Based on the queries listed above. Also, keep in mind that template_content column has XML files, so we would have to preserve the XML. |
|
|
mikgri
Starting Member
39 Posts |
Posted - 2011-03-01 : 16:20:18
|
| You can use something like this: create procedure procedure_name @DatabaseName varchar(128)='', @template1 varchar(10)='', @template2 varchar(10)='', @template3 varchar(10)=''asSET NOCOUNT ON;declare @sql nvarchar(max), @maxvertiszonesetid intdeclare @expression varchar(400), @expression1 varchar(100), @expression2 varchar(100), @expression3 varchar(100)if len(@template1)>0 set @expression1=' and template_group='''+@template1+''''if len(@template2)>0 set @expression2=' and template_group='''+@template2+''''if len(@template3)>0 set @expression3=' and template_group='''+@template3+''''select @expression='where template_group=''ADMIN'''+@expression1+@expression2+@expression3set @sql='use [%db];select template_id, template_name, template_content, template_group, template_section,delete_ind, applicationfrom slxHRScreenTemplates '+@expressionset @sql=replace(@sql, '%db', @DatabaseName)execute sp_executesql @sql--I didn't pass "Admin" as a parameter because it is same for both queries.Don't have data to check how it works. |
 |
|
|
steven.liberman1
Starting Member
15 Posts |
Posted - 2011-03-02 : 14:20:39
|
| Basically I need a dynamic sql stored procedure for this, because I need to replace everything based on template_group correspondence.So Admin field will remain adminManager Field will be replaced by Corp BenefitsPayroll will be replaced by Data ProcHR will be replaced by smartlinx. But I need to preserve XML. |
 |
|
|
steven.liberman1
Starting Member
15 Posts |
Posted - 2011-03-07 : 09:54:19
|
| create procedure WEB_HR_TemplateUpdate {@template_group varchar(1000)}as -- select * from version5_ABCM..slxhrscreentemplates -- select * from version500.slxhrscreentemplates declare @template_id int declare @template_name varchar(10) declare @template_content XML declare @template_section varchar(20) declare @delete_ind int declare @application varchar(10) Begin If version500..slxhrcreentemplates.template_group in ('ADMIN','Manager','Payroll','HR') set @template_id = (select template_id from version5_ABCM..slxhrscreentemplates where template_group = 'Admin' and template_group = 'Corp Benefits' and template_group = 'Data Proc' and template_group = 'Smartlinx') If version500..slxhrcreentemplates.template_group in ('ADMIN','Manager','Payroll','HR') set @template_name = (select template_name from version5_ABCM..slxhrscreentemplates where template_group = 'Admin' and template_group = 'Corp Benefits' and template_group = 'Data Proc' and template_group = 'Smartlinx')This is what I have so far |
 |
|
|
|
|
|
|
|