Issue while inserting hardcode value into column

  • I have declared a table

     declare @Emp table
     (
      no bigint identity(1,1) primary key,
      ms bigint,
                    name varchar(20) not null
     )

     Declare  @stttime datetime ,
       @Etime datetime

    SET @starttime = getdate()
                    --blalblabla  testing a function to see how much time mtaking
       SET @Endtime = getdate()

       Insert into @Emp (ms,'Function')
       Select datediff(ms,@sttime,@etime)

    Why it I showng error invalid colun name at 'Function'; I am trying to insrt some description hardcoded value into Emp table
    Some times it says psedudo code error

     

  • Insert into @Emp (ms,'Function')
    Select datediff(ms,@sttime,@etime)

    Your error message is really telling you the problem here, you're trying to insert data into the columns ms and 'Function', in your table @emp. You're then only supplying one value.

    I'm not actually sure what your aim is here. What are you actually trying to populate your table with?

    Thom~

    Excuse my typos and sometimes awful grammar. My fingers work faster than my brain does.
    Larnu.uk

  • something like this maybe?   (your declared variables didnt match your inserts)

    DECLARE @starttime DATETIME, @Endtime DATETIME;
    SET @starttime = GETDATE();
    WAITFOR DELAY '00:00:02';
    SET @Endtime = GETDATE();

    INSERT INTO @Emp(ms, name)
    SELECT DATEDIFF(ms, @starttime, @Endtime),'test';

    SELECT *FROM @emp;

    ________________________________________________________________
    you can lead a user to data....but you cannot make them think
    and remember....every day is a school day

Viewing 3 posts - 1 through 2 (of 2 total)

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