• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 571
  • Last Modified:

convert sql query to stored procedure

Hi all,

can someone convert this SQL Query into a stored procedure for me please, i learn best by working on comparison from what i have to what i want

Thanks

SELECT tblUsers.*, q.AssetCount
FROM
tblUsers LEFT JOIN
(
SELECT UserID, Count(tblEquipment.ID) as AssetCount FROM tblEquipment LEFT JOIN tblUsers ON tblEquipment.UserID = tblUsers.ID GROUP BY UserID 
) q
ON tblUsers.ID = q.UserID

Open in new window

0
awilderbeast
Asked:
awilderbeast
1 Solution
 
CluskittCommented:
What do you mean, convert to stored procedure? What different result do you want? If you just want the exact same thing, then all you need to do is add:
CREATE PROCEDURE MyProcName AS
and add the query. If you want to introduce variables, you'd do something like:
CREATE PROCEDURE MyProcName
     @MyVar1 int,
     @MyVar2 varchar(10)

AS
--your query
WHERE MyIntField=@MyVar1 AND MyCharField=@MyVar2
0
 
sachitjainCommented:
create procedure Proc1
as
begin
      SELECT tblUsers.*, q.AssetCount
      FROM
      tblUsers LEFT JOIN
      (
            SELECT UserID, Count(tblEquipment.ID) as AssetCount FROM tblEquipment LEFT JOIN tblUsers ON tblEquipment.UserID = tblUsers.ID GROUP BY UserID
      ) q
      ON tblUsers.ID = q.UserID
end
0
 
awilderbeastAuthor Commented:
yeah i figured it out, quite simple really!

Thanks
0

Featured Post

Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now