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

Our new SQL Server Forums are live! Come on over! We've restricted the ability to create new threads on these forums.

SQL Server Forums
Profile | Active Topics | Members | Search | Forum FAQ
Save Password
Forgot your Password?

 All Forums
 SQL Server 2012 Forums
 SQL Server Administration (2012)
 Reply to Topic
 Printer Friendly
Author Previous Topic Topic Next Topic  

Starting Member

9 Posts

Posted - 08/23/2013 :  05:37:56  Show Profile  Reply with Quote
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

Flowing Fount of Yak Knowledge

2242 Posts

Posted - 08/23/2013 :  06:36:18  Show Profile  Reply with Quote
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

Edited by - bandi on 08/23/2013 06:37:37
Go to Top of Page

Starting Member

9 Posts

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

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

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


that was the code i was asking for...
btw query is solved and thanx once again :)
Go to Top of Page
  Previous Topic Topic Next Topic  
 Reply to Topic
 Printer Friendly
Jump To:
SQL Server Forums © 2000-2009 SQLTeam Publishing, LLC Go To Top Of Page
This page was generated in 0.03 seconds. Powered By: Snitz Forums 2000