1

I want to insert into a table an value from variable and an select result.

declare @actual Date
set @actual = getdate()

This is my try:

insert into test (ID, Date) (select ID, @actual from Table)

I get an error Message!!

1
  • 1
    "An error message" - care to share? Those things usually include some useful information - even if you don't know what it means, it's possible that other people could help you. Also, when posting code, please highlight it and hit the {} button. Commented Jan 29, 2013 at 8:44

3 Answers 3

4

use INSERT INTO..SELECT statement,

DECLARE @actual Date
SET @actual = GETDATE()

INSERT INTO test (ID, Date) 
SELECT ID, @actual 
FROM   Tablename
Sign up to request clarification or add additional context in comments.

Comments

1
You can try like this for using a select clause for Insert

insert into test(id,date) select col1,col2 from table;

Comments

0
INSERT INTO TEST
(ID,DATE)
SELECT COLUMN1,COLUMN2 FROM TABLE

Comments

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.