Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chriss Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Variable Convert

Status
Not open for further replies.

Craig0201

Technical User
Oct 11, 2000
1,261
GB
Hi,

I've got 2 tables to store some custom attributes in my app, Custom_Attribute and Custom_Attribute_Value. The data is stored in a varchar field in Custom_Attribute_Value but the 'true' datatype is stored in Custom_Attribute (i.e. a bit or an int is stored in a varchar).

How can I do a convert based on the value returned from Custom_Attribute.DataType?

Craig
 
Not sure if there's an easier way but...

You could build up a SQL String to run and use the EXEC() command to run it.

Try selecting the data into variables so you have:

@Custom_Attribute_Value
@Custom_Attribute

Now build a SQL that uses the CONVERT/CAST functions:

SELECT @SQLString = "SELECT CONVERT(" + @Custom_Attribute" + "," + @Custom_Attribute_Value + ")"

And execute it using EXEC:

EXEC( @SQLString )


Regards,
JJayUK
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top