August 4, 2017 at 6:38 am
How to pass date selection to the below stored procedure?
I have startdate and enddate parameters (these are type of date selection parameters)
Problem is that dates are there in a different table not related to this stored procedure. DO I need to join that table here to pass the date selection?
ALTER PROCEDURE Emp1
@Employee INT,
@EmployeeId INT,
@YearId SMALLINT
AS
BEGIN
SET NOCOUNT ON;
DECLARE
--varibales----
SELECT
@WE = PrED
FROM
dbo.EmpYear
WHERE
YearId = @YearId
SELECT
col1,
col2,
col3
from
dbo.useremp eu
INNER JOIN dbo.Emp
ON eu.Id = e.tId
AND e.YearId = @YearId
AND e.IsDel = 0
LEFT JOIN dbo.EmplCou emce2
ON e.EnMaId = emce2.EnMaId
WHERE
eu.Id = @Employee
ORDER BY
e.CliName,
e.CliId,
e.EmplName
END
August 4, 2017 at 6:49 am
A quick Google and a link to Microsoft docs (specifically look at the 3rd sample T-SQL): https://docs.microsoft.com/en-us/sql/relational-databases/stored-procedures/execute-a-stored-procedure#TsqlProcedure
Without seeming harsh, executing an SP is one of the basics of T-SQL. You should really be looking to up yourself, rather than coming straight to a website to ask how; or if you're being asked to work with T-SQL but have very little knowledge, ask your employee for training. You'll learn better that way.
Edit: one day I'll post without a typo... One day.
Thom~
Excuse my typos and sometimes awful grammar. My fingers work faster than my brain does.
Larnu.uk
August 4, 2017 at 8:10 am
mcfarlandparkway - Friday, August 4, 2017 6:38 AM
I have startdate and enddate parameters (these are type of date selection parameters)
Problem is that dates are there in a different table not related to this stored procedure. DO I need to join that table here to pass the date selection?
If they're used by the stored procedure then they are related to the stored procedure. What you're asking is a design decision, do you use a static set of dates for the entire query? Do the date ranges vary based on the data they are being used to filter in which case a join would be more appropriate?
Viewing 3 posts - 1 through 2 (of 2 total)
You must be logged in to reply to this topic. Login to reply