Click here to Skip to main content
15,889,600 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
hi guys
i have this store procedure

SQL
select * from dbo.DeleteList where (Title2 like '%-%') 
select * from dbo.DeleteList where (Title2 NOT like '%-%') 


and i want get result of first line then result of second line
are you hava an idea?
i use UNION but it not work.
Posted
Updated 9-Oct-13 19:08pm
v2

u can try some thing like...
SQL
select * from dbo.DeleteList 
Order by Case When Title2 like '%-%' Then 1 Else 2 End 
 
Share this answer
 
Hey there,

Have you tried UNION ALL,

SQL
select *from dbo.DeleteList where (Title2 like '%-%') 
UNION ALL
select * from dbo.DeleteList where (Title2 NOT like '%-%')


Hope it helps.

Azee...
 
Share this answer
 
I guess the conditions added are confusing..

If some records are fetched under like '%-%' then obviously then others are not fetched because the they did not satisfy the condition.

Two contradictary opposite conditions is similar in using
SELECT * without any condition

i.e SELECT * FROM TABLE1
where you will get records satisfying both the condition.
 
Share this answer
 
Please check below piece of code

SQL
CREATE Table #Temp
(ID int Identity(1,1),Title Varchar(20))

CREATE Table #Temp2
(ID int,Title Varchar(20))

INSERT INTO #Temp
SELECT 'Test1'
UNION
SELECT 'Test2'
UNION
SELECT 'Test3'
UNION
SELECT 'Test-1'
UNION
SELECT 'Test-2'
UNION
SELECT 'Test-3'

INSERT INTO #Temp2
Select row_number()Over (order by ID),Title FROM #temp Where Title LIKE '%-%'
UNION
Select row_number()Over (order by ID),Title FROM #temp Where Title Not LIKE '%-%'

SELECT * FROM #Temp2 Order BY ID

Drop TABLE #temp
DROP TABLE #Temp2
 
Share this answer
 
select * from dbo.DeleteList where Title2 like '%-%' and Title2 NOT like '%-%'
 
Share this answer
 
Comments
Hemant Singh Rautela 5-Oct-13 10:45am    
result --- now any row found...
two opposite condition check in same query...
:-)
Ranesh M Raj 5-Oct-13 11:27am    
i need full table structure to solve your problem

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900