Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 General SQL Server Forums
 New to SQL Server Programming
 Trim

Author  Topic 

cutiebo2t
Constraint Violating Yak Guru

256 Posts

Posted - 2010-01-31 : 21:09:54
Table Name = Med

Med
med1, med3, med5

I want to create a view that would be viewed like this:

Med
med1
med3
med5

Any help is appreciated. Thanks

khtan
In (Som, Ni, Yak)

17689 Posts

Posted - 2010-01-31 : 21:12:10
use one of the following
CSVTable
fnParseList


KH
[spoiler]Time is always against us[/spoiler]

Go to Top of Page

cutiebo2t
Constraint Violating Yak Guru

256 Posts

Posted - 2010-01-31 : 21:32:28
is it possible without creating a stored procedure?
Go to Top of Page

khtan
In (Som, Ni, Yak)

17689 Posts

Posted - 2010-01-31 : 22:01:09
those are function not stored procedure


KH
[spoiler]Time is always against us[/spoiler]

Go to Top of Page

cutiebo2t
Constraint Violating Yak Guru

256 Posts

Posted - 2010-01-31 : 22:02:18
i really don't understand how.
Go to Top of Page

khtan
In (Som, Ni, Yak)

17689 Posts

Posted - 2010-01-31 : 22:10:39
[code]
begin tran
-- Create a table for testing and for illustration of the function
create table Med
(
csvmed varchar(20)
)

-- Insert some sample data into the testing table
insert into Med (csvmed)
select 'med1, med2, med3' union all
select 'med4, med5, med6'

-- the Query. Which you can convert into a View easily
select stringval as med
from Med m
cross apply dbo.CSVTable(csvmed)

rollback
[/code]


KH
[spoiler]Time is always against us[/spoiler]

Go to Top of Page

cutiebo2t
Constraint Violating Yak Guru

256 Posts

Posted - 2010-01-31 : 22:14:37
am getting this error:
Line 3: Incorrect syntax near 'apply'.
Go to Top of Page

khtan
In (Som, Ni, Yak)

17689 Posts

Posted - 2010-01-31 : 22:16:28
what is the version of your SQL Server ?


KH
[spoiler]Time is always against us[/spoiler]

Go to Top of Page

cutiebo2t
Constraint Violating Yak Guru

256 Posts

Posted - 2010-01-31 : 22:16:58
2000 sir
Go to Top of Page

cutiebo2t
Constraint Violating Yak Guru

256 Posts

Posted - 2010-01-31 : 22:25:14
I got the error when I tried running this script:

select stringval as med
from Med m
cross apply dbo.CSVTable(csvmed)
Go to Top of Page

khtan
In (Som, Ni, Yak)

17689 Posts

Posted - 2010-01-31 : 22:28:57
CROSS APPLY is only available for SQL 2005/2008


KH
[spoiler]Time is always against us[/spoiler]

Go to Top of Page

cutiebo2t
Constraint Violating Yak Guru

256 Posts

Posted - 2010-01-31 : 22:30:17
any option for 2000? :(
Go to Top of Page

khtan
In (Som, Ni, Yak)

17689 Posts

Posted - 2010-01-31 : 22:30:21
for 2000, it will not be easy. What are you trying to achieve here ?


KH
[spoiler]Time is always against us[/spoiler]

Go to Top of Page

cutiebo2t
Constraint Violating Yak Guru

256 Posts

Posted - 2010-01-31 : 22:32:24
i would like to have results that would like like this:

MED
med1
med2
med3
med4
med5
med6

Go to Top of Page

cutiebo2t
Constraint Violating Yak Guru

256 Posts

Posted - 2010-01-31 : 22:47:52
Hi I tried it in 2005 but I got this message:

Invalid object name 'dbo.CSVTable'.
Go to Top of Page

khtan
In (Som, Ni, Yak)

17689 Posts

Posted - 2010-01-31 : 23:38:03
quote:
Originally posted by cutiebo2t

Hi I tried it in 2005 but I got this message:

Invalid object name 'dbo.CSVTable'.



see my 1st post. Get it from the link


KH
[spoiler]Time is always against us[/spoiler]

Go to Top of Page

cutiebo2t
Constraint Violating Yak Guru

256 Posts

Posted - 2010-02-01 : 01:10:41
I got it. What if I want it in a horizontal view. Like this:

med1 med2 med3 med4 med5 med6
Go to Top of Page

madhivanan
Premature Yak Congratulator

22864 Posts

Posted - 2010-02-01 : 01:16:20
quote:
Originally posted by cutiebo2t

I got it. What if I want it in a horizontal view. Like this:

med1 med2 med3 med4 med5 med6


Where do you want to show the data?

Madhivanan

Failing to plan is Planning to fail
Go to Top of Page

cutiebo2t
Constraint Violating Yak Guru

256 Posts

Posted - 2010-02-01 : 01:18:39
in a view in a columnar format. thanks
Go to Top of Page

madhivanan
Premature Yak Congratulator

22864 Posts

Posted - 2010-02-01 : 01:36:12
quote:
Originally posted by cutiebo2t

in a view in a columnar format. thanks


Are you going to display them in a front end application?

Madhivanan

Failing to plan is Planning to fail
Go to Top of Page

cutiebo2t
Constraint Violating Yak Guru

256 Posts

Posted - 2010-02-01 : 01:56:15
no backend
Go to Top of Page
    Next Page

- Advertisement -