SQL Server Forums
Profile | Register | Active Topics | Members | Search | Forum FAQ
 
Register Now and get your question answered!
Username:
Password:
Save Password
Forgot your Password?

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

rssrk
Starting Member

India
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

bandi
Flowing Fount of Yak Knowledge

India
2217 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
--
Chandu

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

rssrk
Starting Member

India
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

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
  Previous Topic Topic Next Topic  
 New 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.05 seconds. Powered By: Snitz Forums 2000