| Author |
Topic |
|
mind_grapes
Yak Posting Veteran
71 Posts |
Posted - 2009-07-29 : 04:36:32
|
| Hello all, I have the following error message in one of my stored procedures but no idea how to rectify it, any help would be brill.ERRORMsg 207, Level 16, State 1, Procedure spGetZonesType, Line 6(in red)Invalid column name 'storeID'Stored ProcedureSELECT zoneID ,ZoneName FROM tblzones WHERE zoneID IN (SELECT DISTINCT fk_zoneID FROM tblStores2Zones WHERE fk_storeID = (storeID)) END |
|
|
madhivanan
Premature Yak Congratulator
22864 Posts |
Posted - 2009-07-29 : 05:11:00
|
| Make sure the column storeID is available in the table tblStores2ZonesMadhivananFailing to plan is Planning to fail |
 |
|
|
mind_grapes
Yak Posting Veteran
71 Posts |
Posted - 2009-07-29 : 05:29:03
|
available? you mean make sure its in that table? it is as fk_storeID, i thought that would have been enough?quote: Originally posted by madhivanan Make sure the column storeID is available in the table tblStores2ZonesMadhivananFailing to plan is Planning to fail
|
 |
|
|
Mangal Pardeshi
Posting Yak Master
110 Posts |
Posted - 2009-07-29 : 05:33:13
|
| what exactly is the storeID? is it a column in tblStores2Zones or some other table? Or a value in fk_storeID column?Mangal Pardeshihttp://mangalpardeshi.blogspot.com |
 |
|
|
mind_grapes
Yak Posting Veteran
71 Posts |
Posted - 2009-07-29 : 05:58:00
|
storeID is a column in another table (tblstores). The column in tblstores2zones is, fk_storeID, that is how the two tables are linked.Im playing around with a stored procedure because I have a problem with some data not being returned to a drop down menu in an ASP page properly. I think it may be becuase of the Stored Procedurequote: Originally posted by Mangal Pardeshi what exactly is the storeID? is it a column in tblStores2Zones or some other table? Or a value in fk_storeID column?Mangal Pardeshihttp://mangalpardeshi.blogspot.com
|
 |
|
|
Mangal Pardeshi
Posting Yak Master
110 Posts |
Posted - 2009-07-29 : 06:04:23
|
| [code]SELECT zoneID ,ZoneNameFROM tblzones WHERE zoneID IN (SELECT DISTINCT Z.fk_zoneID FROM tblStores2Zones as Z JOIN tblstores AS s ON z.fk_storeID = S.storeID)[/code]Mangal Pardeshihttp://mangalpardeshi.blogspot.com |
 |
|
|
mind_grapes
Yak Posting Veteran
71 Posts |
Posted - 2009-07-29 : 06:22:24
|
Ha ha, brilliant it has worked, thank you soooo much, onto the next part of my project.but i have to ask what was i doing wrong? what was the error? You seem to have much knowledge.quote: Originally posted by Mangal Pardeshi
SELECT zoneID ,ZoneNameFROM tblzones WHERE zoneID IN (SELECT DISTINCT Z.fk_zoneID FROM tblStores2Zones as Z JOIN tblstores AS s ON z.fk_storeID = S.storeID) Mangal Pardeshihttp://mangalpardeshi.blogspot.com
|
 |
|
|
mind_grapes
Yak Posting Veteran
71 Posts |
Posted - 2009-07-29 : 06:32:27
|
Nooooo, something is not working properly, hope you can help. let me explain. I have a drop down menu that should display specific records for a shop based on the shops unique id number (storeID) but when i click from shop1 to shop 2, it displays the same zoneID and ZoneName for them all....arr :-(.please save my mind from this madness.RegardsMGquote: Originally posted by Mangal Pardeshi
SELECT zoneID ,ZoneNameFROM tblzones WHERE zoneID IN (SELECT DISTINCT Z.fk_zoneID FROM tblStores2Zones as Z JOIN tblstores AS s ON z.fk_storeID = S.storeID) Mangal Pardeshihttp://mangalpardeshi.blogspot.com
|
 |
|
|
Mangal Pardeshi
Posting Yak Master
110 Posts |
Posted - 2009-07-29 : 06:38:43
|
| Sorry not able to follow you.What is shop1 to shop 2? What is expected at shop1 and shop2? And what is the logic?Mangal Pardeshihttp://mangalpardeshi.blogspot.com |
 |
|
|
mind_grapes
Yak Posting Veteran
71 Posts |
Posted - 2009-07-29 : 06:42:40
|
| Im think i may need to add something to the SQL statement where by it checks the storeid number and fk_store id number match. So it should then bring back data specific to that store/shop? |
 |
|
|
Mangal Pardeshi
Posting Yak Master
110 Posts |
Posted - 2009-07-29 : 06:46:01
|
| yes, may be... :)Mangal Pardeshihttp://mangalpardeshi.blogspot.com |
 |
|
|
mind_grapes
Yak Posting Veteran
71 Posts |
Posted - 2009-07-29 : 07:13:01
|
Let me explain, well try and explain.I have an ASP page that pulls information from a database. the information that is displayed to the user is in a drop down menu. this drop down menu should only disply records that relate specifically to a certain shop / store. This "information" is, what types of displays they have in their shops. displays are things like cabinets, window displays, shelves etc. so for example, shop number 1 should have 2 window displays, 3 cabinets, but shop number 2 should have 1 window display and 4 cabinets.at the moment all shops are showing the same types of displays(zoneNames) and the same number for displays (eg window display = zoneid 1). hope this makes sense.I think i have to set it so the SQL statement checks what value the storeID is and return the the zonesName associated with that store?So i think something like this perhaps? SELECT zoneID ,ZoneName ,storeID FROM tblzones WHERE zoneID IN (SELECT DISTINCT Z.fk_zoneID FROM tblStores2Zones as Z JOIN tblstores AS s ON z.fk_storeID = S.storeID) AND StoreID = FK_storeIDquote: Originally posted by Mangal Pardeshi Sorry not able to follow you.What is shop1 to shop 2? What is expected at shop1 and shop2? And what is the logic?Mangal Pardeshihttp://mangalpardeshi.blogspot.com
|
 |
|
|
Mangal Pardeshi
Posting Yak Master
110 Posts |
Posted - 2009-07-29 : 07:37:00
|
| may be yes!!But You will need to rewrite your query a bit. StoreId column exists is in tblzones table?If not then, my suggestion is - remove the IN clause and rewrite the query using JOIN with tblStores2Zones and tblstores tables.Mangal Pardeshihttp://mangalpardeshi.blogspot.com |
 |
|
|
mind_grapes
Yak Posting Veteran
71 Posts |
Posted - 2009-07-29 : 07:54:49
|
I thought i may. Im very new to this field but the keys areas im using are the followingthe tables im working with are:tblzoneTypescolumns (zoneTypeID - ZoneTypeName) 1 cabinet 2 gondola 3 fish tank 4 window promo 5 triple window promo 6 Memory Display 7 gondola two 8 kioskszoneID | ZoneName | fk_zonetypeID1 Cabinet one - small 12 Cabinet two - middle 13 Cabinet three - large 14 Cabinet four - double bay 15 WINDOW FRONT LEFT 1 56 WINDOW FRONT LEFT 2 58 Memory Display 69 Goldola 2tblStore2Zonesstore2ZoneID | fk_storeID | fk_zoneID | active1 1 1 True2 1 2 True3 1 3 True4 1 5 True5 2 1 True6 2 3 True7 2 5 True8 3 1 True9 3 5 True tblstoresstoreID | StoreNumber | storeName1 1 First Store2 2 second store3 3 Third Store5 4 fourth6 5 fifth store7 6 sixth8 7 seven9 8 eight10 9 nine11 10 ten12 11 eleventhe ASP code is this:SELECT FLOORPLAN LISTINGS <select name="zoneID" id="zoneID"> <option value="0" > - Cabinets - </option><%sSQL = "exec spGetZonesType"SET oRS = oDB.Execute(sSQL)response.Write iZoneID & "-"If Not oRS.EOF Then While Not oRS.EOF %><option value="<%=oRS("zoneTypeName")%>" <% If cint(checkValue(iZoneID)) = ("zoneID") Then response.write " selected " End If %>><%=oRS("zoneTypeName") & "-" & oRS("zoneName")%></option><% oRS.MoveNext WendEnd If %>quote: Originally posted by Mangal Pardeshi may be yes!!But You will need to rewrite your query a bit. StoreId column exists is in tblzones table?If not then, my suggestion is - remove the IN clause and rewrite the query using JOIN with tblStores2Zones and tblstores tables.Mangal Pardeshihttp://mangalpardeshi.blogspot.com
|
 |
|
|
Mangal Pardeshi
Posting Yak Master
110 Posts |
Posted - 2009-07-29 : 08:05:50
|
A complete query may look like thisSELECT Z.zoneID ,Z.ZoneName,S.storeID,zt.ZoneTypeNameFROM tblZone Z INNER JOIN tblzoneTypes AS ZTON Z.fk_zoneTypeID = ZT.zoneTypeID tblStore2Zones AS szON Z.zoneID = SZ.fk_zoneID INNER JOIN tblstores AS SON SZ.fk_storeID = S.storeId Mangal Pardeshihttp://mangalpardeshi.blogspot.com |
 |
|
|
mind_grapes
Yak Posting Veteran
71 Posts |
Posted - 2009-07-29 : 10:17:42
|
| My original Stored procedure was this.SELECT storeID,zoneID,zoneName FROM tblstores s LEFT JOIN tblStores2Zones s2z on storeID = s2z.fk_storeID LEFT JOIN tblZones z on fk_zoneID = z.zoneID LEFT JOIN tblZoneTypes zt on fk_ZoneTypeID = zt.zoneTypeIDWHERE storeid = fk_storeIDbut it didnt work.I just used what you wrote and i get the following error.Msg 102, Level 15, State 1, Procedure spGetZonesType, Line 12Incorrect syntax near 'tblStore2Zones'SELECT Z.zoneID ,Z.ZoneName,S.storeID,zt.ZoneTypeNameFROM tblZone Z INNER JOIN tblzoneTypes AS ZTON Z.fk_zoneTypeID = ZT.zoneTypeID tblStore2Zones AS szON Z.zoneID = SZ.fk_zoneID INNER JOIN tblstores AS SON SZ.fk_storeID = S.storeId |
 |
|
|
mind_grapes
Yak Posting Veteran
71 Posts |
Posted - 2009-07-29 : 10:19:35
|
| sorry it's this linetblStore2Zones AS sz |
 |
|
|
vijayisonly
Master Smack Fu Yak Hacker
1836 Posts |
Posted - 2009-07-29 : 11:34:46
|
A JOIN is missing...try this..SELECT Z.zoneID, Z.ZoneName, S.storeID, zt.ZoneTypeName FROM tblZone Z INNER JOIN tblzoneTypes AS ZT ON Z.fk_zoneTypeID = ZT.zoneTypeID INNER JOIN tblStore2Zones AS sz ON Z.zoneID = SZ.fk_zoneID INNER JOIN tblstores AS S ON SZ.fk_storeID = S.storeId |
 |
|
|
mind_grapes
Yak Posting Veteran
71 Posts |
Posted - 2009-07-30 : 04:29:36
|
| Hi thank you for your post,This unfortunately still brings back all the results, and is not specific to a shop.If i add this:WHERE s.storename ='second shop'all information will be brought back, but again, if i select a different store, then it will again bring back information about the "second shop", because it wont cycle through the table.it has to bring back information that is unique to a shopregardsMG |
 |
|
|
mind_grapes
Yak Posting Veteran
71 Posts |
Posted - 2009-07-30 : 06:53:33
|
| Hi all,With my constant questions on how to get this problems sorted, i felt it only right tell you it has now been sussed.The problem I had was because i wasn't passing a parameter through the query.the final sql query was:CREATE PROCEDURE [dbo].[spGetZonesType]@iStoreID DECIMALASBEGINSELECTzoneID,ZoneName,ZoneTypeNameFROM tblZones zINNER JOIN tblZoneTypes AS ztON z.zoneID = zt.zoneTypeIDINNER JOIN tblstores2zones AS s2zon z.zoneID = s2z.fk_zoneIDinner join tblstores AS son s2z.fk_storeID = s.storeIDWHERE storeID = @iStoreIDENDThanks to all for help in getting it sorted.RegardsMG |
 |
|
|
|