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.

 All Forums
 SQL Server 2012 Forums
 Transact-SQL (2012)
 Rewrite sql query

Author  Topic 

collie
Constraint Violating Yak Guru

400 Posts

Posted - 2013-05-15 : 04:43:36
Hi,

I want to rewrite the following update into a select statement to see what value is returned for the set value.

 update cd  
set cd.PolicyDetailID = isnull((select top 1 ID from CRM.PolicyDetails pd1

where pd1.PolicyID = pd.PolicyID

and pd1.CustomerID = pd.CustomerID

and pd1.CoverageID = pd.CoverageID

and pd1.ContractID = 3743

and pd1.StateCode = 4

and pd1.StartDate < ISNULL(pd1.EndDate,'30000101')

order by pd.ID asc), cd.PolicyDetailID)


CD_PolicyDetailID, pd.ID pd_ID, cd.lastupdatedate

from clm.Claimdata cd

inner join CRM.PolicyDetails pd on pd.ID = cd.PolicyDetailID

and pd.CustomerID = cd.CustomerID

and pd.PolicyID = cd.PolicyID

inner join crm.policy p on p.id=pd.PolicyID

inner join #MatchingCECD tmp1 on tmp1.cdid=cd.id

where pd.ContractID = 1201

and p.CompanyID = 111


Thanks for the help :)

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2013-05-15 : 04:50:37
[code]
select cd.PolicyDetailID,isnull((select top 1 ID from CRM.PolicyDetails pd1

where pd1.PolicyID = pd.PolicyID

and pd1.CustomerID = pd.CustomerID

and pd1.CoverageID = pd.CoverageID

and pd1.ContractID = 3743

and pd1.StateCode = 4

and pd1.StartDate < ISNULL(pd1.EndDate,'30000101')

order by pd.ID asc), cd.PolicyDetailID)


CD_PolicyDetailID, pd.ID pd_ID, cd.lastupdatedate

from clm.Claimdata cd

inner join CRM.PolicyDetails pd on pd.ID = cd.PolicyDetailID

and pd.CustomerID = cd.CustomerID

and pd.PolicyID = cd.PolicyID

inner join crm.policy p on p.id=pd.PolicyID

inner join #MatchingCECD tmp1 on tmp1.cdid=cd.id

where pd.ContractID = 1201

and p.CompanyID = 111
[/code]

------------------------------------------------------------------------------------------------------
SQL Server MVP
http://visakhm.blogspot.com/
https://www.facebook.com/VmBlogs
Go to Top of Page

collie
Constraint Violating Yak Guru

400 Posts

Posted - 2013-05-15 : 10:51:26
Thanks :)
Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2013-05-16 : 00:22:53
welcome

------------------------------------------------------------------------------------------------------
SQL Server MVP
http://visakhm.blogspot.com/
https://www.facebook.com/VmBlogs
Go to Top of Page
   

- Advertisement -