Solved

sql server query in stored procedure

Posted on 2016-08-19
3
29 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
  • 2
3 Comments
 
LVL 69

Accepted Solution

by:
Éric Moreau earned 500 total points
Comment Utility
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
Comment Utility
ok so i just pass a zero or 1


ok
0
 

Author Closing Comment

by:PeterBaileyUk
Comment Utility
thank you
0

Featured Post

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

Performance is the key factor for any successful data integration project, knowing the type of transformation that you’re using is the first step on optimizing the SSIS flow performance, by utilizing the correct transformation or the design alternat…
Having an SQL database can be a big investment for a small company. Hardware, setup and of course, the price of software all add up to a big bill that some companies may not be able to absorb.  Luckily, there is a free version SQL Express, but does …
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 SELECT statement in SQL to return specific rows and columns, with various degrees of sorting and limits in place.

771 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

Need Help in Real-Time?

Connect with top rated Experts

10 Experts available now in Live!

Get 1:1 Help Now