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
 SQL Server 2005 Forums
 Transact-SQL (2005)
 Conversion Fail, Multiple Values
 New Topic  Reply to Topic
 Printer Friendly
Author Previous Topic Topic Next Topic  

bomerso
Starting Member

2 Posts

Posted - 03/19/2013 :  09:04:06  Show Profile  Reply with Quote
I am very new to writing views in SQL, so I've quickly run into an problem that I can't figure out.

I needed to convert a field from type varchar to type int so that I could link it to another table in Crystal Reports. Here's my view:

Create view CR_BillingFilterDataINT as

Select
code
,data_type
,convert(int,data) as DATA
From
billing_filter_data

I found that when the DATA field only contains one value, it works fine. But when DATA has multiple values (example 10, 12, 14) it fails to make the conversion. If I understand it correctly, my view is creating this:

Code / DataType / DATA
1 / 1 / 10,12,14

When I need it to create this:

Code / DataType / DATA
1 / 1 / 10
1 / 1 / 12
1 / 1 / 14

Any help would be appreciated.

webfred
Flowing Fount of Yak Knowledge

Germany
8764 Posts

Posted - 03/19/2013 :  09:36:33  Show Profile  Visit webfred's Homepage  Reply with Quote
comma separated values in a varchar column is a mess...

you can use the seach field in the upper right corner to get some ideas on how to handle that i.e. splitting the data...


Too old to Rock'n'Roll too young to die.
Go to Top of Page

bomerso
Starting Member

2 Posts

Posted - 03/19/2013 :  13:46:28  Show Profile  Reply with Quote
I have looked through several posts, found some great information (http://www.sqlteam.com/article/parsing-csv-values-into-multiple-rows and http://www.sqlexamples.info/SQL/adv_tally10k.htm ), and concluded that this will take more than than I can commit at the moment. Thanks anyway :)
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.05 seconds. Powered By: Snitz Forums 2000