Wrox Programmer Forums
Go Back   Wrox Programmer Forums > Database > SQL Language
|
SQL Language SQL Language discussions not specific to a particular RDBMS program or vendor.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the SQL Language section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old April 18th, 2008, 10:40 AM
Registered User
 
Join Date: Apr 2008
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
Default Cast varchar as int SQL Server 2005

I have a table [tbl_Controls] that contains the Field [ControlValue] nvarchar(250) (Data Example '1,2,3') w/o the '
If I have a single nuber as (Data Example '1') w/o the ', the query works correctly

I need to filter the following, The field [ProductType_ID] Integer

select ProductType_ID,Category from tbl_ProductsCategories
Where ProductType_ID in (Select Cast (ControlValue as integer) from tbl_Controls where controlid = 17)
 
Old April 23rd, 2008, 06:03 AM
Friend of Wrox
 
Join Date: May 2004
Posts: 642
Thanks: 0
Thanked 43 Times in 42 Posts
Default

You cannot cast comma separated list as integer and use.

What you can probably do is create temp table and store this comma separated data in this table and use in SQL query.

Om Prakash
 
Old April 23rd, 2008, 06:09 AM
Friend of Wrox
 
Join Date: May 2004
Posts: 642
Thanks: 0
Thanked 43 Times in 42 Posts
Default

Please check the following link:
http://www.4guysfromrolla.com/webtech/031004-1.shtml


Om Prakash





Similar Threads
Thread Thread Starter Forum Replies Last Post
reg conn to sql server 2005 from vb.net 2005.. veda SQL Server 2005 2 July 1st, 2008 12:16 AM
Error converting data type varchar to int. - SQL baysaa SQL Server ASP 1 March 16th, 2008 11:56 PM
varchar(max) in sql server 2005 vinchellam SQL Server 2005 4 May 31st, 2007 10:32 AM
Text/large varchar fields in SQL server pseudomorph Classic ASP Databases 0 August 16th, 2006 11:50 PM
Data type change from int to Varchar getxyz SQL Server 2000 1 April 29th, 2005 09:59 AM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.