Tuesday, May 5, 2009

Updating in Tbl1 col based on cols from Tbl2 and Tbl3

scenario:This query updates the ModuleId,SubModuleID columns in tbl1 based on PQR column by using the values from the two different tables tbl2 and tbl3 i.e. tbl2.ModuleId and tbl3.SubModuleId if PQR column has in the foramt of ModuleName\SubModuleName.

select (select ModuleID from appmodules where Modulename =
substring(permissionssection,0,charindex('\',permissionssection))) as MainModuleID,(select Max(SubModuleID) from appsubmodules where (SubModulename = substring (permissionssection
,charindex('\',permissionssection)+1,len(permissionssection))) or (Replace(SubModulename,' ','') = substring (permissionssection
,charindex('\',permissionssection)+1,len(permissionssection))) ) as SubModuleID,substring(permissionssection,0,charindex('\',permissionssection)) as start,substring (permissionssection ,charindex('\',permissionssection)+1,len(permissionssection)) as endID from securable.

No comments: