Cathal O 'Donnell
Cathal O 'Donnell

Reputation: 525

SQL Server 2008 - insert into column from 2 different tables

I am wondering how I would have a single column, for example called ClientID, I want to be able to select from two different tables and have all the results go into this column.

This is what I am currently trying but I am getting errors:

SELECT ClientID = ('basic' + CAST(a.BasicCID as VARCHAR(15))) AND =('premium' + CAST(c.PremiumCID as VARCHAR(15)))

I want the output to display something like this

ClientID   Name
-------  --------
basic1   John
basic2   Pat
premium1 Mary
premium2 Sean

Upvotes: 0

Views: 28

Answers (1)

Krishnraj Rana
Krishnraj Rana

Reputation: 6656

Okay, You can do something like this -

Insert into YourTable(ClientID, Name)
  SELECT 'basic' + CAST(a.BasicCID as VARCHAR(15)), Name From BasicTable a
  UNION
  SELECT 'premium' + CAST(c.PremiumCID as VARCHAR(15)), Name From PremiumTable c

Upvotes: 2

Related Questions