Click here to monitor SSC
SQLServerCentral is supported by Red Gate Software Ltd.
 
Log in  ::  Register  ::  Not logged in
 
 
 
        
Home       Members    Calendar    Who's On


Add to briefcase

error while casting a column name Expand / Collapse
Author
Message
Posted Wednesday, February 06, 2013 11:37 PM
Grasshopper

GrasshopperGrasshopperGrasshopperGrasshopperGrasshopperGrasshopperGrasshopperGrasshopper

Group: General Forum Members
Last Login: Today @ 3:35 AM
Points: 11, Visits: 109
Set FormattedValue = CASE
When rg.ReferredFieldType='NUM'
Then CAST(#PointedMslValues.Value AS NUMERIC(18,cAST(rg.ReferredDecimalPoints) )

more cases .
END

I am generating a dynamic query which is giving error actually it requires integer value while casting not a column name
Post #1416819
Posted Thursday, February 07, 2013 12:56 AM
Forum Newbie

Forum NewbieForum NewbieForum NewbieForum NewbieForum NewbieForum NewbieForum NewbieForum Newbie

Group: General Forum Members
Last Login: Tuesday, February 19, 2013 2:31 AM
Points: 3, Visits: 246
Can you able to say what is type of FormattedValue column.

FormattedValue column strict to type so you can not assign other type except type of FormattedValue column.

Thanks,

Nishant
ID:nishantcomp2512
Post #1416841
Posted Thursday, February 07, 2013 1:19 AM
Ten Centuries

Ten CenturiesTen CenturiesTen CenturiesTen CenturiesTen CenturiesTen CenturiesTen CenturiesTen Centuries

Group: General Forum Members
Last Login: Saturday, May 18, 2013 6:46 PM
Points: 1,074, Visits: 1,076
ALI100 (2/6/2013)
Set FormattedValue = CASE
When rg.ReferredFieldType='NUM'
Then CAST(#PointedMslValues.Value AS NUMERIC(18,cAST(rg.ReferredDecimalPoints) )

more cases .
END

I am generating a dynamic query which is giving error actually it requires integer value while casting not a column name


If you are creating a dynmaic query then try the output be like NUMERIC (18,9) ..so use concatenation of strings..


~ demonfox
___________________________________________________________________
Wondering what I would do next , when I am done with this one
Post #1416855
Posted Thursday, February 07, 2013 1:23 AM


SSCertifiable

SSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiable

Group: General Forum Members
Last Login: Today @ 8:51 AM
Points: 5,608, Visits: 10,970
ALI100 (2/6/2013)
Set FormattedValue = CASE
When rg.ReferredFieldType='NUM'
Then CAST(#PointedMslValues.Value AS NUMERIC(18,cAST(rg.ReferredDecimalPoints) )

more cases .
END

I am generating a dynamic query which is giving error actually it requires integer value while casting not a column name


CAST(rg.ReferredDecimalPoints AS datatype)

However, it's unlikely to be as simple as this because it will have to be stringified to work. Can you post the whole query?


“Write the query the simplest way. If through testing it becomes clear that the performance is inadequate, consider alternative query forms.” - Gail Shaw

For fast, accurate and documented assistance in answering your questions, please read this article.
Understanding and using APPLY, (I) and (II) Paul White
Hidden RBAR: Triangular Joins / The "Numbers" or "Tally" Table: What it is and how it replaces a loop Jeff Moden
Exploring Recursive CTEs by Example Dwain Camps
Post #1416856
Posted Thursday, February 07, 2013 1:42 AM
Grasshopper

GrasshopperGrasshopperGrasshopperGrasshopperGrasshopperGrasshopperGrasshopperGrasshopper

Group: General Forum Members
Last Login: Today @ 3:35 AM
Points: 11, Visits: 109
FormattedValue VARCHAR(MAX)
Post #1416875
Posted Thursday, February 07, 2013 5:29 AM
Forum Newbie

Forum NewbieForum NewbieForum NewbieForum NewbieForum NewbieForum NewbieForum NewbieForum Newbie

Group: General Forum Members
Last Login: Tuesday, February 19, 2013 2:31 AM
Points: 3, Visits: 246
Thanks Grasshopper for quick reply.

you can not use cAST(rg.ReferredDecimalPoints) to add decimal point to numeric data type.you can not use variable inside numeric bracket.you have to pass static value.

you can accomplish this by Substring function in sql.select only few char after decimal point from varchar data.

i thinks to pick only few char after decimal point is easy that casting to impossible numeric type as we want data should be in varchar.

Nishant
ID:nishantcomp2512
Post #1416993
« Prev Topic | Next Topic »

Add to briefcase

Permissions Expand / Collapse