| 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 |
 |
|
|
asuni
Yak Posting Veteran
55 Posts |
Posted - 2010-03-25 : 02:28:55
|
| Can i use ISNULL function for this ? |
 |
|
|
asuni
Yak Posting Veteran
55 Posts |
Posted - 2010-03-25 : 02:29:26
|
| ya, i am also thinking this , thank you very much :) |
 |
|
|
asuni
Yak Posting Veteran
55 Posts |
Posted - 2010-03-25 : 02:29:57
|
| thank you very much :) |
 |
|
|
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 TBLMsg 245, Level 16, State 1, Line 1Conversion failed when converting the varchar value 'NOT ASSIGNED' to data type smallint.thanks |
 |
|
|
asuni
Yak Posting Veteran
55 Posts |
Posted - 2010-03-25 : 02:48:46
|
| Any help please |
 |
|
|
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) |
 |
|
|
asuni
Yak Posting Veteran
55 Posts |
Posted - 2010-03-25 : 03:03:09
|
| you are right thank you very much |
 |
|
|
pk_bohra
Master Smack Fu Yak Hacker
1182 Posts |
Posted - 2010-03-25 : 03:06:41
|
WELCOME Regards,BohraI am here to learn from Masters and help new bees in learning. |
 |
|
|
|