0

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

1
  • The correct syntax for this in tsql is Select ... Into tablename from ... Commented Mar 24, 2017 at 17:44

1 Answer 1

1

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.

Sign up to request clarification or add additional context in comments.

3 Comments

If i want to store the output into new table. How to write a query for that?
above is the method, did you notice into tablename part?
Yaa, I forgot to refresh the DB. That why i cannot see the new table.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.