本文介绍了如何更改查询,所以我只需要传递一个字符串而不是3个字符串的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
这是我的查询,目前我需要通过 postCode,State和Suburb ,
如何更改查询,所以我只需要传递一个字符串,如 strDetailOfAddress ,然后得到我需要的东西。
Here is my query,currently I need pass the postCode ,State and Suburb,
How do I change my query so I only need pass one string like strDetailOfAddress, then get what I need.
SELECT Area.AreaName AS Zone
FROM [LLM_RL].[dbo].[Area] INNER JOIN
[LLM_RL].[dbo].[AreaStructure] ON Area.AreaStructureKey = AreaStructure.AreaStructureKey INNER JOIN
[LLM_RL].[dbo].[AreaSuburb] ON Area.AreaKey = AreaSuburb.AreaKey AND AreaStructure.AreaStructureKey = AreaSuburb.AreaStructureKey INNER JOIN
[LLM_RL].[dbo].[Suburb] ON AreaSuburb.SuburbKey = Suburb.SuburbKey INNER JOIN
[LLM_RL].[dbo].[Area] AS Area_1 ON Area.ParentKey = Area_1.AreaKey
WHERE ((AreaStructure.AreaStructureName LIKE 'Web%') AND (Area.AreaName LIKE 'Can' + ' Air Zone%') And (PostCode='2601')) and (Suburb='CANBERRA') and (Suburb.State='ACT')
推荐答案
DECLARE @strDetailOfAddress VARCHAR(400)
DECLARE @PostCode VARCHAR(100)
DECLARE @Suburb VARCHAR(100)
DECLARE @State VARCHAR(100)
set @PostCode='2601'
set @Suburb='CANBERRA'
set @State='ACT'
SET @strDetailOfAddress=''
SET @strDetailOfAddress=' And (PostCode='''+@PostCode+''')) and (Suburb='''+@Suburb+''') and (Suburb.State='''+@State+''')'
print(@strDetailOfAddress)
-- GET SALARY DETAILS FOR A MONTH IN PIVOT FORM
DECLARE @SEL NVARCHAR(MAX)
SET @SEL='SELECT Area.AreaName AS Zone
FROM [LLM_RL].[dbo].[Area] INNER JOIN
[LLM_RL].[dbo].[AreaStructure] ON Area.AreaStructureKey = AreaStructure.AreaStructureKey INNER JOIN
[LLM_RL].[dbo].[AreaSuburb] ON Area.AreaKey = AreaSuburb.AreaKey AND AreaStructure.AreaStructureKey = AreaSuburb.AreaStructureKey INNER JOIN
[LLM_RL].[dbo].[Suburb] ON AreaSuburb.SuburbKey = Suburb.SuburbKey INNER JOIN
[LLM_RL].[dbo].[Area] AS Area_1 ON Area.ParentKey = Area_1.AreaKey
WHERE ((AreaStructure.AreaStructureName LIKE ''Web%'') AND (Area.AreaName LIKE ''Can'' + '' Air Zone%'')''
'+ CAST(@strDetailOfAddress AS NVARCHAR(MAX)) +'
group by [Employee],parameter_type_name '
print @SEL
exec(@SEL)
希望这可以帮到你。
hope this might help you.
这篇关于如何更改查询,所以我只需要传递一个字符串而不是3个字符串的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!