Pregunta

I have a table with data like enter image description here

I want all the records from the table but which the record having EnquiryStatus=1 and order by LastAttendendedDate should come on the top and remaining records should come after those records. I tried to select twice with where condition and tried to union all them, But with that union all not allowing me to order by on different ways. I can do it in c# by retriving the data as two table and merge them as single. But I want it in sql..

EDITS:

I want something like

Select * From EnquiryMaster A Where  A.BranchID=16 and EnquiryStatus=1  ORDER BY A.CreatedDate Desc     
UNION ALL
Select * From EnquiryMaster A Where  A.BranchID=16 and EnquiryStatus in(0,2,3) ORDER BY EnquiryStatus,A.CreatedDate Desc
¿Fue útil?

Solución 2

Try this

select * from your_table
order by case when EnquiryStatus=1 then LastAttendendedDate end DESC

Otros consejos

SELECT * FROM TABLE_NAME WHERE ORDER BY CASE WHEN EnquiryStatus='1' THEN LastAttendendedDate END DESC 

You can use this in sql.

Licenciado bajo: CC-BY-SA con atribución
No afiliado a StackOverflow
scroll top