I am working on SQL Server 2016.
I want to know is there anyway I can create a permanent or temporary table with column names present in another table?
See the table: MAINTAGS and its code below. I want DOB as my first column, POB as 2nd and so on...
Currently there are 12 names in my MAINTAGS table, so new table will have total 12 columns.
More names can be added as well in MAINTAGS
ID_MAINTAGS NAMES_MAINTAGS
============== ==============
1 DOB
2 POB
3 citizen
4 nationality
5 Additional Sanctions Information
6 Passport
7 National ID No.
8 Email Address
9 Gender
10 a.k.a.
11 Linked To:
12 Phone Number
IF OBJECT_ID('dbo.MAINTAGS', 'U') IS NOT NULL
DROP TABLE dbo.MAINTAGS;
CREATE TABLE MAINTAGS(ID_MAINTAGS INT IDENTITY(1,1), NAMES_MAINTAGS VARCHAR(MAX));
INSERT INTO MAINTAGS (NAMES_MAINTAGS)
VALUES
('DOB'),('POB'),('citizen'),('nationality'),
('Additional Sanctions Information'), ('Passport'),('National ID No.'),
('Email Address'),('Gender'),('a.k.a.'),('Linked To: ')