Solved

sql server query in stored procedure

Posted on 2016-08-19
3
40 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

The Ultimate Checklist to Optimize Your Website

Websites are getting bigger and complicated by the day. Video, images, custom fonts are all great for showcasing your product/service. But the price to pay in terms of reduced page load times and ultimately, decreased sales, can lead to some difficult decisions about what to cut.

Question has a verified solution.

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

Slowly Changing Dimension Transformation component in data task flow is very useful for us to manage and control how data changes in SSIS.
Recently we ran in to an issue while running some SQL jobs where we were trying to process the cubes.  We got an error saying failure stating 'NT SERVICE\SQLSERVERAGENT does not have access to Analysis Services. So this is a way to automate that wit…
This video shows, step by step, how to configure Oracle Heterogeneous Services via the Generic Gateway Agent in order to make a connection from an Oracle session and access a remote SQL Server database table.
Viewers will learn how to use the UPDATE and DELETE statements to change or remove existing data from their tables. Make a table: Update a specific column given a specific row using the UPDATE statement: Remove a set of values using the DELETE s…

707 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