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
 SQL Server 2005 Forums
 Transact-SQL (2005)
 NULLVALUE function

Author  Topic 

asuni
Yak Posting Veteran

55 Posts

Posted - 2010-03-25 : 02:22:41
Hi All,
I am using SQL Server 2005.
I need one help.
Is there any function like

For Ex: NULLVALUE(x, y)
so that if 'x' is null this function return the 'y' value.

ex:SELECT @NULLVALUE(DEPTNO,'NOT ASSIGNED') FROM EMP;
in this if DEPTNO is null, it return 'NOT ASSIGNED' value.

thank you very much.

haroon2k9
Constraint Violating Yak Guru

328 Posts

Posted - 2010-03-25 : 02:28:44
SELECT ISNULL(DEPTNO,'NOT ASSIGNED') FROM TBL
Go to Top of Page

asuni
Yak Posting Veteran

55 Posts

Posted - 2010-03-25 : 02:28:55
Can i use ISNULL function for this ?
Go to Top of Page

asuni
Yak Posting Veteran

55 Posts

Posted - 2010-03-25 : 02:29:26
ya, i am also thinking this ,

thank you very much :)
Go to Top of Page

asuni
Yak Posting Veteran

55 Posts

Posted - 2010-03-25 : 02:29:57
thank you very much :)
Go to Top of Page

asuni
Yak Posting Veteran

55 Posts

Posted - 2010-03-25 : 02:33:53
sorry in ISNULL, the second variable should be number,
the query is giving error as :

SELECT ISNULL(DEPTNO,'NOT ASSIGNED') FROM TBL

Msg 245, Level 16, State 1, Line 1
Conversion failed when converting the varchar value 'NOT ASSIGNED' to data type smallint.


thanks
Go to Top of Page

asuni
Yak Posting Veteran

55 Posts

Posted - 2010-03-25 : 02:48:46
Any help please
Go to Top of Page

pk_bohra
Master Smack Fu Yak Hacker

1182 Posts

Posted - 2010-03-25 : 02:53:33
ISNull will return the value specified in the function. It doesn't look for the returned datatype.

You are getting the error because u are returning varchar and assigning it to Numeric field.

Returned datatype matters when u are assigning the value returned by this function.

You need to use Isnull(DEPTNO,0)
Go to Top of Page

asuni
Yak Posting Veteran

55 Posts

Posted - 2010-03-25 : 03:03:09
you are right thank you very much
Go to Top of Page

pk_bohra
Master Smack Fu Yak Hacker

1182 Posts

Posted - 2010-03-25 : 03:06:41
WELCOME

Regards,
Bohra

I am here to learn from Masters and help new bees in learning.
Go to Top of Page
   

- Advertisement -