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
 General SQL Server Forums
 New to SQL Server Programming
 how to cast

Author  Topic 

Chinni
Yak Posting Veteran

95 Posts

Posted - 2008-08-25 : 11:12:50
Can you plz help me in this

declare @amount NUMERIC(10,0)
set @amount =(select income from incometable )

select
case

when (@amount IN ('NA','na','n/a','N/A'))
then 'ACF'
when (@amount = 0)
then 'PT'
else 'NA'

end

I declare @amount as numeric but i should pass characters ,how to cast

Thanks

SwePeso
Patron Saint of Lost Yaks

30421 Posts

Posted - 2008-08-25 : 11:19:53
[code]SELECT CASE
WHEN @Amount LIKE '%N%A%' THEN 'ACF'
WHEN @Amount = 0 THEN 'PT'
ELSE 'NA'
END[/code]


E 12°55'05.25"
N 56°04'39.16"
Go to Top of Page

Chinni
Yak Posting Veteran

95 Posts

Posted - 2008-08-25 : 11:31:16
thanks for your quick respnse

I declare @ amount as numeric(10,0) and i am passing a character.....

they asked me cast when i am doing this ......can you suggest me how to cast
Go to Top of Page

SwePeso
Patron Saint of Lost Yaks

30421 Posts

Posted - 2008-08-25 : 11:33:17
No need to cast.
declare @amount as varchar(2583)
select @amount = income from incometable

SELECT CASE
WHEN @Amount LIKE '%N%A%' THEN 'ACF'
WHEN @Amount = '0' THEN 'PT'
ELSE 'NA'
END



E 12°55'05.25"
N 56°04'39.16"
Go to Top of Page

Chinni
Yak Posting Veteran

95 Posts

Posted - 2008-08-25 : 11:54:35
thanks a lot...
Go to Top of Page

madhivanan
Premature Yak Congratulator

22864 Posts

Posted - 2008-08-26 : 04:08:53
quote:
Originally posted by Chinni

Can you plz help me in this

declare @amount NUMERIC(10,0)
set @amount =(select income from incometable )

select
case

when (@amount IN ('NA','na','n/a','N/A'))
then 'ACF'
when (@amount = 0)
then 'PT'
else 'NA'

end

I declare @amount as numeric but i should pass characters ,how to cast

Thanks



How can you store these values 'NA','na','n/a','N/A' in a NUMERIC datatype variable?

Madhivanan

Failing to plan is Planning to fail
Go to Top of Page

SwePeso
Patron Saint of Lost Yaks

30421 Posts

Posted - 2008-08-26 : 04:21:35
He isn't.
Also the set @amount = (select ...) thingy is flawed, but I saved that to another topic.



E 12°55'05.25"
N 56°04'39.16"
Go to Top of Page

Transact Charlie
Master Smack Fu Yak Hacker

3451 Posts

Posted - 2008-08-26 : 05:39:11
Chinni,

I'm sure this isn't doing what you expect it to.

The line

select @amount = income from incometable


Is actually assigning *each* entry in incometable to the variable 1 at a time in no set order so you end up with the *last* entry in the table (ordered in some arbitrary way by the server). Are you sure this is what you want? I don't think so.

I think what you actually want is this.


SELECT
ic.<WHATEVER IDENTIFYING COLUMN EXISTS>
, CASE
WHEN ic.[income] IN ('NA','na','n/a','N/A') THEN 'ACF'
WHEN ic.[income] = '0' THEN 'PT'
ELSE 'NA'
END AS [Income Type]
FROM
incometable ic


Which will return a list of income Types with whatever other details you need. (replace the <WHATEVER IDENTIFYING COLUMN EXISTS> with your won columns)

-------------
Charlie
Go to Top of Page

Transact Charlie
Master Smack Fu Yak Hacker

3451 Posts

Posted - 2008-08-26 : 05:40:51
quote:
Originally posted by Peso

He isn't.
Also the set @amount = (select ...) thingy is flawed, but I saved that to another topic.



E 12°55'05.25"
N 56°04'39.16"




Has he raised a duplicate post?

-------------
Charlie
Go to Top of Page

SwePeso
Patron Saint of Lost Yaks

30421 Posts

Posted - 2008-08-26 : 06:19:08
No, not yet.
But it will come soon...

You explained why in your earlier post.


E 12°55'05.25"
N 56°04'39.16"
Go to Top of Page

Transact Charlie
Master Smack Fu Yak Hacker

3451 Posts

Posted - 2008-08-26 : 06:26:20
quote:
Originally posted by Peso

No, not yet.
But it will come soon...

You explained why in your earlier post.


E 12°55'05.25"
N 56°04'39.16"




hmmmm... Giving them exactly what they ask for, even though its probably not what they actually want... Bit of a hard lesson.

I like it! Maybe I should delete my post and wait for the subsequent "Why it no work???? -- URGENT!!!" posts.

-------------
Charlie
Go to Top of Page

SwePeso
Patron Saint of Lost Yaks

30421 Posts

Posted - 2008-08-26 : 07:19:06
I have noticed giving them too much information makes them nervous and not reading anything from the suggestions.



E 12°55'05.25"
N 56°04'39.16"
Go to Top of Page
   

- Advertisement -