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.

 All Forums
 General SQL Server Forums
 New to SQL Server Programming
 search columns

Author  Topic 

Msandlana
Starting Member

33 Posts

Posted - 2008-01-31 : 06:01:01
Hi everyone
I am trying to create a stored procedure that will searches any of the following different columns of the defferent tables

[dbo].[Store]
[dbo].[StoreType]
[dbo].[City]
[dbo].[Province]



--I joined the 4 tables below

SELECT dbo.Store.Store, dbo.Province.Province, dbo.City.City, dbo.StoreType.StoreType
FROM Store INNER JOIN
dbo.Province ON dbo.Store.ProvinceID = dbo.Province.ProvinceId INNER JOIN
dbo.City ON dbo.Store.CityID = dbo.City.CityId INNER JOIN
dbo.StoreType ON dbo.Store.StoreTypeID = dbo.StoreType.StoreTypeId Where 1 = 1

--I have 2 parameters
1.@varSearch varchar(50)
2.@varProvince varchar(50)

in @varSearch parameter You can search any thing from [dbo].[Store].Store or [dbo].[StoreType].StoreType or [dbo].[City].City
and @varProvince will be [dbo].[Province].Province

the output must show every Store,StoreType or City in the province

SwePeso
Patron Saint of Lost Yaks

30421 Posts

Posted - 2008-01-31 : 06:15:09
WHERE @varSearch IN (Store, StoreType, City)
AND Provice = @Province



E 12°55'05.25"
N 56°04'39.16"
Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2008-01-31 : 06:21:07
WHERE ([dbo].[Store].Store =@varSearch
or [dbo].[StoreType].StoreType=@varSearch
or [dbo].[City].City=@varSearch )
and [dbo].[Province].Province=@varProvince
Go to Top of Page

Msandlana
Starting Member

33 Posts

Posted - 2008-01-31 : 08:02:59
I Tried those It Desplay more than the required results it will show stores from other provinces
Go to Top of Page

SwePeso
Patron Saint of Lost Yaks

30421 Posts

Posted - 2008-01-31 : 08:18:34
When you copied or rewrote visakh's suggestion, I think you missed some paranthesises.
Make sure the paranthesises are at the right places and try again.



E 12°55'05.25"
N 56°04'39.16"
Go to Top of Page

Msandlana
Starting Member

33 Posts

Posted - 2008-02-01 : 03:08:47
Thanks
Go to Top of Page

SwePeso
Patron Saint of Lost Yaks

30421 Posts

Posted - 2008-02-01 : 03:13:33
That's why Copy and Paste was invented...



E 12°55'05.25"
N 56°04'39.16"
Go to Top of Page
   

- Advertisement -