SQL query:
SELECT *
FROM Account
WHERE (type <>100000002 ? Id='something': Id=null)
but it shows error :
Incorrect syntax near '?'
Please help me.
SQL query:
SELECT *
FROM Account
WHERE (type <>100000002 ? Id='something': Id=null)
but it shows error :
Incorrect syntax near '?'
Please help me.
This is for SQL Server. IIF
is not available in SQL Server 2008 or earlier.
SELECT *
FROM Account
WHERE
Id=IIF(type<> 100000002,"something",null )
If you are using SQL Server 2008 or earlier, then try this.
SELECT *
FROM Account
WHERE (Id= CASE WHEN type <>100000002 THEN 'something' ELSE null END)
You can do this :
SELECT *
FROM Account
where (type <>100000002 and Id='something') or (type =100000002 and id is null)
or
SELECT *
FROM Account
where isnull(id,'_null_')= case when type <>100000002 then 'something' else isnull(id,'_null_') end
SELECT *
FROM Account
WHERE (Id= CASE WHEN type <>100000002 THEN 'something' ELSE null END)
Use the following:
SELECT *
FROM Account
WHERE (Id= CASE WHEN type != 100000002 THEN 'something' ELSE null END)
or
SELECT *
FROM Account
WHERE (Id= CASE WHEN type <> 100000002 THEN 'something' ELSE null END)
SELECT *
FROM Account
where (type <>100000002 and Id='something') or (type =100000002)
You can use case when...then in sql please see this link http://blog.sqlauthority.com/2007/04/14/sql-server-case-statementexpression-examples-and-explanation/