Not the correct syntax near the keyword "DECLARE"

This public forum is for user-to-user discussions of PHPMaker. Note that this is not support forum.
Post Reply
vladsn07
User
Posts: 13

Not the correct syntax near the keyword "DECLARE"

Post by vladsn07 »

There is a query that is perfectly executed in the sql managment studio. Sql server 2014
But if you create a view, the message goes:
Not the correct syntax near the keyword "DECLARE"

DECLARE @tbComputers table (ComputerId int)
INSERT INTO @tbComputers
SELECT ComputerId FROM we_Computers WHERE dbo.IsComputerNested(ComputerId, 3) = 1

SELECT

c.ComputerName as "Имя компьютера",

ISNULL(s.ActivityTime, 0) ,
ISNULL(s.ForegroundTime - s.ActivityTime, 0) ,
ISNULL(s.ForegroundTime, 0),

FROM we_Computers c
INNER JOIN @tbComputers tc ON tc.ComputerId = c.ComputerId
LEFT JOIN (SELECT

    ComputerId,

    SUM(sa.ActivityTime) As ActivityTime,

    SUM(sa.ForegroundTime) As ForegroundTime

  FROM we_SummaryActivities sa

  WHERE sa.LogDate >= '01.01.2017' AND sa.LogDate <= '20.03.2017'
 AND sa.ComputerId IN (SELECT ComputerId FROM @tbComputers)

  GROUP BY ComputerId) s ON s.ComputerId = c.ComputerId

mobhar
User
Posts: 11660

Post by mobhar »

Please try to always use Database View as possible instead of using Custom View.


Webmaster
User
Posts: 9425

Post by Webmaster »

A view expects a SELECT statement, you cannot create a view with multiple statements. You'd better create a stored procedure and create a view to execute the stored procedure.


vladsn07
User
Posts: 13

Post by vladsn07 »

I have a stored procedure. How to send parameters to the procedure?


Post Reply