Merge two queries into one

Gurpreet Singh Randhawa
Gurpreet Singh Randhawa used Ask the Experts™
on
I want to merge the query into one

select id
				from dbo.table1 with(nolock)
				where cid = 622
if recordfromabove neq form.value then proceed the follow code				
update table1
					set id = 22
					where cid = 	622		

Open in new window

Comment
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®
Doug BishopDatabase Developer
Commented:
update table1
set id = case when id < 0 then 22 else id end
where cid =       622
Most Valuable Expert 2012
Distinguished Expert 2018
Commented:
Not fully understanding what you are wanting but possibly something like:
update table1
      set id = 22
      where cid =       622       and id != form.value
after the first query i am doing this

<cfif GetInfo.id NEQ arguments.id> then update </cfif>

Open in new window

both the above are failing, if i try, think it like this

<cfquery name="getinfo">
select id
				from dbo.table1 with(nolock)
				where cid = 622
</cfquery>
<cfif GetInfo.id NEQ arguments.id>			
update table1
					set id = #arguments.id#
					where cid = 	622
</cfif>

Open in new window

Most Valuable Expert 2012
Distinguished Expert 2018

Commented:
I see no need to select the id first then update.  A single update should work fine.

Can you post sample data and expected results based on the arguments.id value selected?

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial