Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 General SQL Server Forums
 New to SQL Server Programming
 Sql server Command

Author  Topic 

hyder.inam
Starting Member

1 Post

Posted - 2011-10-07 : 07:22:36
hi
i want to know some thing about Tsql
this query works fine on oracle but i want to make it work on sql server

SELECT * from Table_name
Where id = Nvl(some_Parameter, id)
AND name = Nvl(Parameter_name, Name)

What is the function used instead of nvl in sql server

above query work like if we want to search on id or name or both the query will show required result

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2011-10-07 : 07:24:51
[code]
SELECT * from Table_name
Where id = coalesce(some_Parameter, id)
AND name = coalesce(Parameter_name, Name)

another way

SELECT * from Table_name
Where (id = some_Parameter or some_Parameter is null)
AND (name = Parameter_name or Parameter_name is null)
[/code]

------------------------------------------------------------------------------------------------------
SQL Server MVP
http://visakhm.blogspot.com/

Go to Top of Page

Cindyaz
Yak Posting Veteran

73 Posts

Posted - 2011-10-07 : 11:04:36
also check for isnull() function.
[url]http://msdn.microsoft.com/en-us/library/ms184325.aspx [/url]

Go to Top of Page
   

- Advertisement -