Mehram
asked on
Conditionala where clause in sql query
SQL Server 2005
in sql query to construct a where clause for
if host_name() = 'MATEEN' then
unit_code = '21'
else
ignore unit code matching and show all records
end if
I tried
where ( unit_code = '21' and host_name() = 'MATEEN') or 1=1 )
but it is showing all records in all machines including MATEEN'S P.C.
in sql query to construct a where clause for
if host_name() = 'MATEEN' then
unit_code = '21'
else
ignore unit code matching and show all records
end if
I tried
where ( unit_code = '21' and host_name() = 'MATEEN') or 1=1 )
but it is showing all records in all machines including MATEEN'S P.C.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Oh no,
it is working, thanks
it is working, thanks
welcome, Mehram..
ASKER
WHERE unit_code = (CASE WHEN host_NAME() = 'MATEEN' then '21' ELSE unit_code end)
cannot be else unit_code end , I want to show records of all units if user is not mateen.