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 2012 Forums
 SQL Server Administration (2012)
 function

Author  Topic 

rssrk
Starting Member

9 Posts

Posted - 2013-08-23 : 05:37:56
i am creating a function named as drcr which returns value as varchar.
now the condition is like that-
if number is positive then result should be like that dr(135)=135(cr)
if number is negative then result should be like that dr(-25)= 25(dr)
i had created function of drcr which returns value as varchar
now can i get code for the above condition ??
create function drcr
(
@text nvarchar(140)
)
returns varchar
as begin

bandi
Master Smack Fu Yak Hacker

2242 Posts

Posted - 2013-08-23 : 06:36:18
what is dr/cr here.. I'm not getting your point... Can you explain in detail..
What type of data you will pass?
You can check for -ve/+ve values by using SIGN(expression) function

For negative values, SIGN returns -1
For positive values, SIGN returns 1
--
Chandu
Go to Top of Page

rssrk
Starting Member

9 Posts

Posted - 2013-08-23 : 08:35:00
create function [dbo].[drcr]
(
@n float
)
returns nvarchar(20)
as begin

if(@n>0)
return CONVERT(nvarchar(20),@n)+' (cr)'

return CONVERT(nvarchar(20),@n*(-1))+' (dr)'
end

GO

that was the code i was asking for...
btw query is solved and thanx once again :)
Go to Top of Page
   

- Advertisement -