Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations TouchToneTommy on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

2 fields 1 record change to 2 records in new query

Status
Not open for further replies.

cdw0308

Technical User
Oct 8, 2003
181
US
I have an existing table that has a field cblcode1 and cblcode2. cblcode1 always has data in it and cblcode2 is null sometimes and has data on other records.

I need to create a query that can output the single record into multiple records when cblcode1 and cblcode2 both have data in it. As well as show all cblcode1 records

ex.
current table
autonum cblcode1 cblcode2
1 452d 452c
2 532a 532b
3 562f <null>

new query

autonum cblcode
1 452d
2 452c
3 532a
4 532b
5 562f

Any help in creating this query would be greatly appreciated.




 
Code:
select cblcode1 As cblcode from thetable

union all

select cblcode2 As cblcode from thetable
where cblcode2 IS NOT NULL
 
Forgot to add ...

To get your AutoNumber field you can use the above as input to a maketable query like this
Code:
Select cblCode INTO myNewTable

From (

select cblcode1 As cblcode from thetable

union all

select cblcode2 As cblcode from thetable
where cblcode2 IS NOT NULL) As X

and then create an AutoNumber column
Code:
ALTER TABLE myNewTable ADD COLUMN AutoNum Counter(1,1)

Unfortunately you can't create an on-the-fly Autonum field in a query.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top