Can you use an asterisk (*) to filter a column in a WHERE clause in SQL Server 2008?

for example

SELECT * FROM movies WHERE director=* 
+8
sql sql-server select sql-server-2008
source share
7 answers

No, you will need to use the LIKE operator and the wildcard%:

 SELECT * FROM movies WHERE director like '%'; 
+11
source share

You can use LIKE;

 SELECT * FROM movies WHERE director LIKE '%' --all SELECT * FROM movies WHERE director LIKE 'john landis' --exact SELECT * FROM movies WHERE director LIKE 'steve%berg' --with wildcard 
+5
source share
 WHERE director like '%' 

this is the syntax

+1
source share

For this you need to use LIKE and wildcards:

 select * from movies where director like '%' 
+1
source share

If you are looking for results with ANY director, you can simply leave the WHERE director= completely.

If you want to do a partial match, you can do a WHERE director like '%Lucas%' , which will return the equivalent of *LUCAS* .

+1
source share

If you are looking for the director represented by * , you will have to enclose it between single quotes:

 SELECT * FROM movies WHERE director='*' 

If you are looking for any director, just leave where .

0
source share
 select * from movies where director like '%' 

This will NOT return every row: rows with the null directive will be omitted (at least with MSSQL).

0
source share

All Articles