Why does this query ask me to declare the table when I already have?

My Issue is that the last query in this sproc is saying that I need to declare @N but I already have any ideas?

DECLARE @t TABLE
    (Smpinstanceid UNIQUEIDENTIFIER)

    INSERT INTO @t

    (Smpinstanceid)

    SELECT  t.SmpInstanceid
    FROM Tasks t
    WHERE t.Completed IS NOT NULL and t.SmpInstanceID is not null

DECLARE @N TABLE
(SMPinstanceid UNIQUEIDENTIFIER,[Count] INT)

INSERT INTO @N
(SMPinstanceid,[COUNT])

     SELECT Smpinstanceid,COUNT (Smpinstanceid) AS [Count]
                         FROM   @t
                         GROUP BY Smpinstanceid




            UPDATE Tasks
            SET    StepNum = @n.Count
            WHERE Tasks.SmpInstanceID = @n.smpinstanceid
END
GO

Answers


There is no reference to @n in the update query. You will need to do your update with a subquery, or with a 'from' clause (if this is sql server)

update tasks
  SET StepNum = (select Count from @n 
                     where Tasks.SmpInstanceID = @n.smpinstanceid ) 

or

update tasks
  set stepnum = n.count
  from tasks
    inner join @n as n
      on (Tasks.SmpInstanceID = n.smpinstanceid)

Need Your Help

How to make my box model is well displayed?

border margin css

I don't understand why the margin-top CSS property is not displayed in my divs with class .inner. Moreover I don't understand why the border of my first .inner div overflows his parent.

How do you add a lot of strings together?

string batch-file

I am trying to add a lot of strings (with number based names, from 11 to 103) together, then echo it.

About UNIX Resources Network

Original, collect and organize Developers related documents, information and materials, contains jQuery, Html, CSS, MySQL, .NET, ASP.NET, SQL, objective-c, iPhone, Ruby on Rails, C, SQL Server, Ruby, Arrays, Regex, ASP.NET MVC, WPF, XML, Ajax, DataBase, and so on.