Wrox Programmer Forums

Need to download code?

View our list of code downloads.

Go Back   Wrox Programmer Forums > Database > SQL Language
Password Reminder
Register
| FAQ | Members List | Search | Today's Posts | Mark Forums Read
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 tens of thousands of software programmers and website developers including Wrox book authors and readers. As a guest, you can read any forum posting. By joining today you can post your own programming questions, respond to other developers’ questions, and eliminate the ads that are displayed to guests. Registration is fast, simple and absolutely free .
DRM-free e-books 300x50
Reply
 
Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old April 18th, 2008, 10:40 AM
Registered User
 
Join Date: Apr 2008
Location: St. Joseph, MO, USA.
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)
Reply With Quote
  #2 (permalink)  
Old April 23rd, 2008, 06:03 AM
Friend of Wrox
Points: 2,473, Level: 20
Points: 2,473, Level: 20 Points: 2,473, Level: 20 Points: 2,473, Level: 20
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: May 2004
Location: India
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
Reply With Quote
  #3 (permalink)  
Old April 23rd, 2008, 06:09 AM
Friend of Wrox
Points: 2,473, Level: 20
Points: 2,473, Level: 20 Points: 2,473, Level: 20 Points: 2,473, Level: 20
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: May 2004
Location: India
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
Reply With Quote
Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are Off


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



All times are GMT -4. The time now is 01:49 AM.


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