Please start any new threads on our new
site at https://forums.sqlteam.com. We've got lots of great SQL Server
experts to answer whatever question you can come up with.
Author |
Topic |
Cursor join
Starting Member
8 Posts |
Posted - 2013-01-06 : 10:43:30
|
HI,i have created a sp. i need to pass two or three values while executing.here is Sp..pls guide create PROCEDURE [dbo].[Get_EMP_Details] ( @dt_Prm_Fromdate datetime, @dt_Prm_Todate datetime, @vc_prm_country varchar(50), @vc_prm_city varchar(50) ) AS BEGIN SET NOCOUNT ON; SELECT Name,city travelled FROM EMPloyee INNER JOIN city_Master cm ON EMPloyee.in_city_ID_pK = cm.in_city_ID_fK WHERE (dt_Travelled_Date >=@dt_Prm_Fromdate) and (dt_Returned_Date <=@dt_Prm_Todate) and in_city_type in( @vc_prm_city) and(country_Master.Country_Name in (@vc_prm_country) END --exec [Get_EMP_Detailst] '15/NOV/2012','15/DEC/2012','Australia','perth'(EXCECUTING PROPERLY)--exec [Get_EMP_Detailst] '15/NOV/2012','15/DEC/2012','Australia','sydney'((EXCECUTING PROPERLY))I want these two results should come together when i execute my pROC as below--exec [Get_EMP_Detailst] '15/NOV/2012','15/DEC/2012','Australia','perth,sydney'I know this is not the proper syntax for the procedure.it will be helpful if the proper solution is provided using cursor or whateverrgds..cursor join |
|
Cursor join
Starting Member
8 Posts |
Posted - 2013-01-06 : 11:34:26
|
any guidance? |
|
|
jackv
Master Smack Fu Yak Hacker
2179 Posts |
|
Cursor join
Starting Member
8 Posts |
Posted - 2013-01-06 : 12:41:46
|
Thanks 4 de reply jack...i m totally confused with the links...can u provide me a sample SP.Thanks in Advance!! |
|
|
bandi
Master Smack Fu Yak Hacker
2242 Posts |
Posted - 2013-01-07 : 01:11:06
|
hi first create a function to split the comma separated values and then access function with in your SP..and in_city_type in(SELECT * FROM dbo.fnSplit(@vc_prm_city, ',')) and(country_Master.Country_Name in (SELECT * FROM dbo.fnSplit(@vc_prm_country, ',')) -- This is the code for fnSplitIF OBJECT_ID('[dbo].[fnSplit]') IS NOT NULL DROP FUNCTION [dbo].[fnSplit]GOCREATE FUNCTION dbo.fnSplit( @sInputList VARCHAR(8000) -- List of delimited items , @sDelimiter VARCHAR(8000) = ',' -- delimiter that separates items) RETURNS @List TABLE (item VARCHAR(8000))BEGINDECLARE @sItem VARCHAR(8000)WHILE CHARINDEX(@sDelimiter,@sInputList,0) <> 0 BEGIN SELECT @sItem=RTRIM(LTRIM(SUBSTRING(@sInputList,1,CHARINDEX(@sDelimiter,@sInputList,0)-1))), @sInputList=RTRIM(LTRIM(SUBSTRING(@sInputList,CHARINDEX(@sDelimiter,@sInputList,0)+LEN(@sDelimiter),LEN(@sInputList)))) IF LEN(@sItem) > 0 INSERT INTO @List SELECT @sItem ENDIF LEN(@sInputList) > 0 INSERT INTO @List SELECT @sInputList -- Put the last item inRETURNENDGO--Testselect * from fnSplit('1,22,333,444,,5555,666', ',')select * from fnSplit('1 22 333 444 5555 666', ' ') --Chandu |
|
|
Cursor join
Starting Member
8 Posts |
Posted - 2013-01-07 : 12:02:47
|
thanks a lot chandu..it works... |
|
|
visakh16
Very Important crosS Applying yaK Herder
52326 Posts |
Posted - 2013-01-07 : 23:43:03
|
if filtering dataset is small you could even usecreate PROCEDURE [dbo].[Get_EMP_Details] ( @dt_Prm_Fromdate datetime, @dt_Prm_Todate datetime, @vc_prm_country varchar(50), @vc_prm_city varchar(50) ) AS BEGIN SET NOCOUNT ON; SELECT Name,city travelled FROM EMPloyee INNER JOIN city_Master cm ON EMPloyee.in_city_ID_pK = cm.in_city_ID_fK WHERE (dt_Travelled_Date >=@dt_Prm_Fromdate) and (dt_Returned_Date <=@dt_Prm_Todate) and ',' + @vc_prm_city + ',' LIKE '%,' + in_city_type + ',%' and(country_Master.Country_Name in (@vc_prm_country) END ------------------------------------------------------------------------------------------------------SQL Server MVPhttp://visakhm.blogspot.com/ |
|
|
bandi
Master Smack Fu Yak Hacker
2242 Posts |
Posted - 2013-01-07 : 23:49:31
|
quote: Originally posted by Cursor join thanks a lot chandu..it works...
Welcome--Chandu |
|
|
|
|
|
|
|