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
 General SQL Server Forums
 New to SQL Server Programming
 Variable type
 New Topic  Reply to Topic
 Printer Friendly
Author Previous Topic Topic Next Topic  

goligol
Posting Yak Master

120 Posts

Posted - 06/20/2012 :  11:54:47  Show Profile  Reply with Quote
I want to define the following variable and define a format for it:

,Employee = case
when ..

else
end

where should I define the format for example float for Employee.
Cuz sinse I have not defined any format for it, it goes fine through crating the view but displaying that view I get the following error:

Msg 8115, Level 16, State 8, Line 2
Arithmetic overflow error converting varchar to data type numeric.


thx

RickD
Slow But Sure Yak Herding Master

United Kingdom
3560 Posts

Posted - 06/20/2012 :  12:07:08  Show Profile  Reply with Quote
Post your whole case statement, you need to convert something, but we can't tell you what without seeing the statement.
Go to Top of Page

goligol
Posting Yak Master

120 Posts

Posted - 06/20/2012 :  12:22:41  Show Profile  Reply with Quote
ALTER VIEW [dev].[CBP_BLS_2009]
as

SELECT [fipstate]
,[fipscty]
,[naics]
,["empflag"]
,["emp_nf"]
,["emp"]
,["qp1_nf"]
,["qp1"]
,["ap_nf"]
,["ap"]
,["est"]
,employees = case
when ["emp"] ='0' then (["n1_4"]*2.5 + ["n5_9"]*7 + ["n10_19"]*15 + ["n20_49"]*35 + ["n50_99"]*75 + ["n100_249"]*175 + ["n250_499"]*375 +
["n500_999"]*750 + ["n1000"]*1000 + ["n1000_1"]*1000 + ["n1000_2"]*1000 + ["n1000_3"]*1000 + ["n1000_4"]*1000)
else ["emp"]
end
,["n1_4"]
,["n5_9"]
,["n10_19"]
,["n20_49"]
,["n50_99"]
,["n100_249"]
,["n250_499"]
,["n500_999"]
,["n1000"]
,["n1000_1"]
,["n1000_2"]
,["n1000_3"]
,["n1000_4"]
,["censtate"]
,["cencty"]
FROM [trade].[dev].[CountyBusinessPattern_2009]
Go to Top of Page

jimf
Flowing Fount of Yak Knowledge

USA
2868 Posts

Posted - 06/20/2012 :  12:34:13  Show Profile  Reply with Quote
is EMP a string or a number? Your case statement can't return two different data types.

Jim

Everyday I learn something that somebody else already knew
Go to Top of Page

goligol
Posting Yak Master

120 Posts

Posted - 06/20/2012 :  13:40:54  Show Profile  Reply with Quote
EMP is a number.
Go to Top of Page

jimf
Flowing Fount of Yak Knowledge

USA
2868 Posts

Posted - 06/20/2012 :  14:06:36  Show Profile  Reply with Quote
Strange that EMP is a number but you refer to it as a string "when ["emp"] ='0' then " If EMP really is a numeric data type and not just something that looks like a number, then one of the columns you are doing the math on must not be numeric. Could you provide the DDL for [trade].[dev].[CountyBusinessPattern_2009] ?

Jim

Everyday I learn something that somebody else already knew
Go to Top of Page

goligol
Posting Yak Master

120 Posts

Posted - 06/20/2012 :  16:32:15  Show Profile  Reply with Quote
How should I creat DDL:-(
Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

India
48033 Posts

Posted - 06/20/2012 :  19:45:17  Show Profile  Reply with Quote
just script out table as create from SSMS and post it



------------------------------------------------------------------------------------------------------
SQL Server MVP
http://visakhm.blogspot.com/

Go to Top of Page

goligol
Posting Yak Master

120 Posts

Posted - 06/21/2012 :  10:27:17  Show Profile  Reply with Quote
all the variables are VarChar but I have created the new variable employee which shows it is a numeric
Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

India
48033 Posts

Posted - 06/21/2012 :  17:43:07  Show Profile  Reply with Quote
see if it has precision and scale value to accomodate values you're passing

------------------------------------------------------------------------------------------------------
SQL Server MVP
http://visakhm.blogspot.com/

Go to Top of Page

goligol
Posting Yak Master

120 Posts

Posted - 06/22/2012 :  12:40:55  Show Profile  Reply with Quote
Thank youuuuuuuu
Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

India
48033 Posts

Posted - 06/22/2012 :  22:34:43  Show Profile  Reply with Quote
One typical scenario where I've seen this happening is case where you dont explicitly specify precision scale values when casting and it assumes default values whereas actual values you're getting overflows it

------------------------------------------------------------------------------------------------------
SQL Server MVP
http://visakhm.blogspot.com/

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.12 seconds. Powered By: Snitz Forums 2000