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
 SQL Server 2000 Forums
 SQL Server Development (2000)
 How to convert a field value into table records

Author  Topic 

d
Starting Member

26 Posts

Posted - 2001-12-17 : 17:56:13
I have a table called as A.
It has 2 fields called course_code, course_code_group.

e.g. course_code = 'A', course_code_group = 'ASD','ASDDF','ADEF','EFR'

Now, I want to create a new table called as B with fields course_code, course_code_group.

However, I want the values in the table to be as follows:
course_code = 'A', course_code_group = 'ASD'
course_code = 'A', course_code_group = 'ASDDF'
course_code = 'A', course_code_group = 'ADEF'
course_code = 'A', course_code_group = 'EFR'

How can I do it?

I really appreciate your help.

robvolk
Most Valuable Yak

15732 Posts

Posted - 2001-12-17 : 18:00:39
First, please don't start a new thread with the same question. It confuses people and prevents us from answering your question.

http://www.sqlteam.com/forums/topic.asp?TOPIC_ID=11488

Second, search SQL Team for CSV:

http://www.sqlteam.com/SearchResults.asp?SearchTerms=csv

And look at some dynamic SQL:

http://www.sqlteam.com/item.asp?ItemID=4599
http://www.sqlteam.com/item.asp?ItemID=4619

One or more of these will solve your problem.

Go to Top of Page

d
Starting Member

26 Posts

Posted - 2001-12-17 : 18:04:35
Thanks a lot for your suggestion. I will look at the solution suggested by you.

Also, the reason why I put it as a new topic was because I thought this was a different topic/question. However, next time I will continue on the same thread.

Once again, thanks a lot.

Go to Top of Page

d
Starting Member

26 Posts

Posted - 2001-12-17 : 22:41:48
Your suggestion was really great.
I looked at the websites that you advised and found the required solution.

I have another question.
e.g. in the new table B,
course_code = 'A', course_code_group = 'ALL'

If 'ALL' is the value, then I want to have my final value look like as follows:
select * from employee

This means 'ALL' means no criteria to be used.

However, if the values in the new table B is as follows:
course_code = 'A', course_code_group = 'AAA'
then I want to have my final value look like
select * from employee
where course_code_group in (select course_code_group from B where course_code = 'A')

Is there a way that when I am writing my select statement, can I check if 'ALL' exists in the course_code_group value or not. If it does, then do not use course_code_group condition else use it???

Please let me know your suggestion.

Go to Top of Page
   

- Advertisement -