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.
| Author |
Topic |
|
pnasz
Posting Yak Master
101 Posts |
Posted - 2010-10-19 : 04:02:22
|
| how to write a funtion to show negative number as n/Ai have a computed coloumn in a table overtimeif the difference is negative i want to display text na other wise the no |
|
|
webfred
Master Smack Fu Yak Hacker
8781 Posts |
Posted - 2010-10-19 : 04:04:13
|
No need for a function to write.Show your SELECT statement please. No, you're never too old to Yak'n'Roll if you're too young to die. |
 |
|
|
pnasz
Posting Yak Master
101 Posts |
Posted - 2010-10-19 : 04:11:49
|
| its a computed columni wrote the formula like this, if it is negative i want to display NAotherwise the difference(datediff(minute,[FirstIn],[FirstOut])/(60.0)-datediff(minute,[EmpSIN],[EmpSOut])/(60.0)) |
 |
|
|
Devart
Posting Yak Master
102 Posts |
Posted - 2010-10-19 : 04:17:12
|
| Hi,For example:case when 0>(datediff(minute,[FirstIn],[FirstOut])/(60.0)-datediff(minute,[EmpSIN],[EmpSOut])/(60.0)) then 'N/A' else cast((datediff(minute,[FirstIn],[FirstOut])/(60.0)-datediff(minute,[EmpSIN],[EmpSOut])/(60.0)) as varchar(20)) endBest regards,Devart,SQL Server Tools:dbForge Schema ComparedbForge Data ComparedbForge Query Builder |
 |
|
|
pnasz
Posting Yak Master
101 Posts |
Posted - 2010-10-19 : 04:22:54
|
| is this function or i can write simply in my query |
 |
|
|
webfred
Master Smack Fu Yak Hacker
8781 Posts |
Posted - 2010-10-19 : 04:24:54
|
Note that the datatype of a computed column is defined implicitly by the calculation expression.So your original computed column is of a numeric datatype.If you want to assign a value like 'N/A' then there is type mismatch between numeric and character.Hence Devart has converted the column to varchar.Consider this when using this column... No, you're never too old to Yak'n'Roll if you're too young to die. |
 |
|
|
webfred
Master Smack Fu Yak Hacker
8781 Posts |
Posted - 2010-10-19 : 04:26:01
|
quote: Originally posted by pnasz is this function or i can write simply in my query
It is the expression for your computed column. No, you're never too old to Yak'n'Roll if you're too young to die. |
 |
|
|
pnasz
Posting Yak Master
101 Posts |
Posted - 2010-10-19 : 04:28:11
|
| thanx a lot for your helpregards |
 |
|
|
|
|
|
|
|