Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Conditional where statement

Status
Not open for further replies.

zsyed

MIS
Dec 25, 2011
73
CA
Having a syntax error and can someone help?

select imtpartid, imtCreatedDate from parttransactions where imtpartid = 'XYZ' and imtpartrevisionid = 'A' and (case imtsource when 9 then (imtCreatedDate = (select max(A.imtCreatedDate) from parttransactions A where A.imtpartid = parttransactions.imtpartid and A.imtpartrevisionid = parttransactions.imtpartrevisionid) and imtTransactionType = 2)
else (imtCreatedDate = (select max(A.imtCreatedDate) from parttransactions A where A.imtpartid = parttransactions.imtpartid and A.imtpartrevisionid = parttransactions.imtpartrevisionid)) end)
 
This may get you started down the right path. I don't vouch for the last part of the statement, and this was not tested against any dataset, just parsed for syntax.

Code:
select imtpartid, imtCreatedDate from parttransactions 
where imtpartid = 'XYZ' and imtpartrevisionid = 'A' and 
	imtCreatedDate = 
	(case when imtsource = 9 
		then 
		 
			(select max(A.imtCreatedDate) 
			from parttransactions A 
			where A.imtpartid = parttransactions.imtpartid 
			and A.imtpartrevisionid = parttransactions.imtpartrevisionid)
		 --and caseimttransactiontype = 2
		else 
	
		(select max(A.imtCreatedDate) 
		from parttransactions A 
		where A.imtpartid = parttransactions.imtpartid 
		and A.imtpartrevisionid = parttransactions.imtpartrevisionid) 
	end)
		and caseimtTransactionType = case when imtsource = 9
		then
		 2
		 else
		 caseimtTranscationType
		end

-----------
With business clients like mine, you'd be better off herding cats.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top