insert values in table

  • hi

    how can i add something like this in table

    account's value

    insert into @temp1('account's value')

    getting error?

  • Use the following

    insert into @temp1 select "account's value"

    or

    insert into@ temp1 select 'account''s value')

    GulliMeel

    Finding top n Worst Performing queries[/url]
    Improve the performance of Merge Join(special case)
    How to Post Performance Problem -Gail Shaw[/url]

  • Look up the INSERT statement syntax in Books Online.

    Really not enough info to tell you more, but then you already know that.

  • Gullimeel (5/25/2012)


    Use the following

    insert into @temp1 select "account's value"

    Msg 207, Level 16, State 1, Line 2

    Invalid column name 'account's value'.

    or

    insert into@ temp1 select 'account''s value')

    Msg 102, Level 15, State 1, Line 2

    Incorrect syntax near 'temp1'.

  • Link to INSERT documentation: http://msdn.microsoft.com/en-us/library/ms174335(v=sql.105).aspx

    Example code:

    DECLARE @temp1 AS TABLE

    (

    account_id char(5) NOT NULL

    CHECK (account_id LIKE '[A-Z][A-Z][0-9][0-9][0-9]'),

    as_of_date date NOT NULL

    CHECK (as_of_date <= CONVERT(date, GETDATE())),

    balance money NOT NULL,

    PRIMARY KEY (account_id, as_of_date)

    )

    INSERT INTO @temp1

    (account_id, as_of_date, balance)

    VALUES

    ('AF167', '2012-05-25', $504.91),

    ('AF167', '2012-05-26', $761.33),

    ('AF167', '2012-05-27', $664.87),

    ('DQ042', '2012-05-26', $730.55),

    ('DQ042', '2012-05-27', $709.72);

    SELECT

    t.account_id,

    t.as_of_date,

    t.balance

    FROM @temp1 AS t

    ORDER BY

    t.account_id,

    t.as_of_date;

  • This will work:

    --Creating table

    Create Table Ex

    (ac varchar(30) )

    --Insert Query For Your Requirement

    Insert Into Ex Values('Account''s Value')

    --Checking the Inserted Value

    Select * From Ex

    Vinu Vijayan

    For better and faster solutions please check..."How to post data/code on a forum to get the best help" - Jeff Moden[/url] 😉

  • thanks everyone

  • riya_dave (5/29/2012)


    thanks everyone

    You're welcome 🙂

    Vinu Vijayan

    For better and faster solutions please check..."How to post data/code on a forum to get the best help" - Jeff Moden[/url] 😉

  • use

    insert into @temp1('account'+'''+'s value')

Viewing 9 posts - 1 through 8 (of 8 total)

You must be logged in to reply to this topic. Login to reply