Anish varma Adduri
Anish varma Adduri

Reputation: 599

Error while creating a table from the values of two tables

I am new to sql. I was just trying to create and store data into a table from the values of two tables

1 st table has UserName. 2nd table has password.

So, I have written a sql query with gets both values from two tables and display it in a single table.

      Create table tablename as
select
       T1.username,
       T2.Password
from
       Table1.T1,
       Table2.T2
where
       T1.UserId = T2.UserId;

Here in both tables UserId is common.

I am getting error while executing this statement.

The error is InCorrect Syntax. Error is near SELECT statement.

Can you help me Please,

Thanks in advance

Upvotes: 0

Views: 43

Answers (1)

Gordon Linoff
Gordon Linoff

Reputation: 1269873

SQL Server does not support CREATE TABLE AS. Instead, use INTO:

select T1.username, T2.Password
into tablename
from Table1.T1 join
     Table2.T2
     on T1.UserId = T2.UserId;

Notice that I also fixed your join syntax. Although the use of commas in the FROM clause does not generate an error, it should.

Upvotes: 1

Related Questions