SQL Server Forums
Profile | Register | Active Topics | Members | Search | Forum FAQ
 
Register Now and get your question answered!
Username:
Password:
Save Password
Forgot your Password?

 All Forums
 SQL Server 2012 Forums
 Transact-SQL (2012)
 Rewrite sql query
 New Topic  Reply to Topic
 Printer Friendly
Author Previous Topic Topic Next Topic  

collie
Constraint Violating Yak Guru

399 Posts

Posted - 05/15/2013 :  04:43:36  Show Profile  Reply with Quote
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

India
52325 Posts

Posted - 05/15/2013 :  04:50:37  Show Profile  Reply with Quote

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


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

collie
Constraint Violating Yak Guru

399 Posts

Posted - 05/15/2013 :  10:51:26  Show Profile  Reply with Quote
Thanks :)
Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

India
52325 Posts

Posted - 05/16/2013 :  00:22:53  Show Profile  Reply with Quote
welcome

------------------------------------------------------------------------------------------------------
SQL Server MVP
http://visakhm.blogspot.com/
https://www.facebook.com/VmBlogs
Go to Top of Page
  Previous Topic Topic Next Topic  
 New Topic  Reply to Topic
 Printer Friendly
Jump To:
SQL Server Forums © 2000-2009 SQLTeam Publishing, LLC Go To Top Of Page
This page was generated in 0.06 seconds. Powered By: Snitz Forums 2000