Solved

sql server query in stored procedure

Posted on 2016-08-19
3
38 Views
Last Modified: 2016-08-19
I have this query in a stored procedure:

is it possible for me to pass a parameter to it of some sort so that it could do a slightly different piece of sql.
the difference in this case would be not including the first left join?



USE [Dictionary]
GO
/****** Object:  StoredProcedure [dbo].[usp_GetBulkDescStrings]    Script Date: 19/08/2016 17:05:35 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO

ALTER PROCEDURE [dbo].[usp_GetBulkDescStrings]

AS
BEGIN
select strshort, StrShortTag, [dbo].[TblWords].ClientName, [dbo].TblVehCat.VehCategory
FROM [dbo].[TblWords] LEFT JOIN [TblWordTags] ON [TblWords].ClientCodeWordPosition = [TblWordTags].ClientCodeWordPosition LEFT JOIN [TblVehCat] ON [TblWords].ClientCode = [TblVehCat].ClientCode
WHERE [TblWordTags].ClientCodeWordPosition Is Not Null
group by strshort, StrShortTag, [dbo].[TblWords].ClientName, [dbo].TblVehCat.VehCategory
order by ClientName
END

Open in new window

0
Comment
Question by:PeterBaileyUk
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
3 Comments
 
LVL 70

Accepted Solution

by:
Éric Moreau earned 500 total points
ID: 41762655
sure it is possible. check this:
alter PROCEDURE dbo.usp_GetBulkDescStrings
	@paramWithoutJoin int
AS
BEGIN
	-- SET NOCOUNT ON added to prevent extra result sets from
	-- interfering with SELECT statements.
	SET NOCOUNT ON;

    -- Insert statements for procedure here
	IF @paramWithoutJoin = 0 
	BEGIN 
		select strshort, StrShortTag, [dbo].[TblWords].ClientName, [dbo].TblVehCat.VehCategory
		FROM [dbo].[TblWords] 
		LEFT JOIN [TblWordTags] ON [TblWords].ClientCodeWordPosition = [TblWordTags].ClientCodeWordPosition 
		LEFT JOIN [TblVehCat] ON [TblWords].ClientCode = [TblVehCat].ClientCode
		WHERE [TblWordTags].ClientCodeWordPosition Is Not Null
		group by strshort, StrShortTag, [dbo].[TblWords].ClientName, [dbo].TblVehCat.VehCategory
		order by ClientName
	END 
	ELSE
    BEGIN
--your other query
		select *
		FROM [dbo].[TblWords] 
    END 
END

Open in new window

0
 

Author Comment

by:PeterBaileyUk
ID: 41762709
ok so i just pass a zero or 1


ok
0
 

Author Closing Comment

by:PeterBaileyUk
ID: 41762711
thank you
0

Featured Post

Instantly Create Instructional Tutorials

Contextual Guidance at the moment of need helps your employees adopt to new software or processes instantly. Boost knowledge retention and employee engagement step-by-step with one easy solution.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Retrieve a Registry value using SCCM 2012. 2 43
Using Sum with Case When within a query 9 44
SQL Query (lookup) 8 57
T-SQL: Need to trim a single leading space 7 58
Slowly Changing Dimension Transformation component in data task flow is very useful for us to manage and control how data changes in SSIS.
I have a large data set and a SSIS package. How can I load this file in multi threading?
Via a live example, show how to shrink a transaction log file down to a reasonable size.
Viewers will learn how to use the SELECT statement in SQL to return specific rows and columns, with various degrees of sorting and limits in place.

738 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question