Author |
Topic |
osirisa
Constraint Violating Yak Guru
289 Posts |
Posted - 2007-10-15 : 16:00:08
|
Hi: |
|
tkizer
Almighty SQL Goddess
38200 Posts |
Posted - 2007-10-15 : 16:02:20
|
quote: Originally posted by osirisa I am having huge problems writing stored procedure with multiple cursors.
That would be your first problem. I'm sure you don't need multiple cursors or any at all. The ambiguous error means that the column exists in more than one table in your query. You need to tell it which one to use by TableName.ColumnName method or AliasName.ColumnName method.Tara KizerMicrosoft MVP for Windows Server System - SQL Serverhttp://weblogs.sqlteam.com/tarad/ |
|
|
osirisa
Constraint Violating Yak Guru
289 Posts |
Posted - 2007-10-15 : 17:00:07
|
Thank You Tara, but as you can see I separate both tables with a and b. I have tried to assign "a" before group_code but it doesn't work. Any other suggestion. Please keep in mind that I am new to this world. You have to give me an example of your respond in order for me to understand your idea.Thanks!!! |
|
|
tkizer
Almighty SQL Goddess
38200 Posts |
Posted - 2007-10-15 : 17:03:02
|
You haven't assigned an alias before every group_code. Remember that you are getting group_code back from the * as well.Tara KizerMicrosoft MVP for Windows Server System - SQL Serverhttp://weblogs.sqlteam.com/tarad/ |
|
|
osirisa
Constraint Violating Yak Guru
289 Posts |
Posted - 2007-10-15 : 17:04:50
|
For example ----You mean group_code As Primary. ? |
|
|
tkizer
Almighty SQL Goddess
38200 Posts |
Posted - 2007-10-15 : 17:06:44
|
Every place where you have it, you must specify which table to grab it from. Hint: you'll need to get rid of your select * in order for this to work.Tara KizerMicrosoft MVP for Windows Server System - SQL Serverhttp://weblogs.sqlteam.com/tarad/ |
|
|
osirisa
Constraint Violating Yak Guru
289 Posts |
Posted - 2007-10-15 : 17:11:46
|
If I get rid of the first Select (*)-- This query is a Select within a Select statement I need the first Select to join both queries.---Select * FromSELECT a.group_code,a.station_nbr, a.beg_eff_date, a.end_eff_dateFrom TIES_Temp.dbo.station_group,TIES_Temp.dbo.group_detailwhere(dateadd(month,-1,getdate()) Between beg_eff_date and end_eff_date)and (TIES_Temp.dbo.group_detail.group_type = 'NPN') and(TIES_Temp.dbo.station_group.group_code = TIES_Temp.dbo.group_detail.group_code))a,Select station_nbr, count(station_nbr) as ErrorDuplicateFrom TIES_Temp.dbo.station_groupGROUP BY station_nbrHAVING (COUNT(station_nbr) > 1 ) bWhere a.station_nbr = b.station_nbrHere is the Error Message if I remove the first Select statementServer: Msg 170, Level 15, State 1, Line 5Line 5: Incorrect syntax near ')'.Server: Msg 170, Level 15, State 1, Line 10Line 10: Incorrect syntax near 'b'. |
|
|
tkizer
Almighty SQL Goddess
38200 Posts |
Posted - 2007-10-15 : 17:15:59
|
You are missing my point. Hopefully someone else will come along to help you as I don't have the time right now to go back and forth like this.Tara KizerMicrosoft MVP for Windows Server System - SQL Serverhttp://weblogs.sqlteam.com/tarad/ |
|
|
osirisa
Constraint Violating Yak Guru
289 Posts |
Posted - 2007-10-15 : 17:18:12
|
Thanks for the help |
|
|
osirisa
Constraint Violating Yak Guru
289 Posts |
Posted - 2007-10-15 : 17:59:11
|
I can believe it, 38 people read my sql query problem and ONLY ONE reply to my request for help.Thanks!!!! It's great to know that we help each other in this community. |
|
|
Van
Constraint Violating Yak Guru
462 Posts |
Posted - 2007-10-15 : 18:03:47
|
It seemed Tara was helping you just fine...no need for anyone else to jump in. Or maybe we just don't know the answer either... |
|
|
tkizer
Almighty SQL Goddess
38200 Posts |
Posted - 2007-10-15 : 18:05:55
|
quote: Originally posted by osirisa I can believe it, 38 people read my sql query problem and ONLY ONE reply to my request for help.Thanks!!!! It's great to know that we help each other in this community.
That kind of reply will not get you anywhere.Tara KizerMicrosoft MVP for Windows Server System - SQL Serverhttp://weblogs.sqlteam.com/tarad/ |
|
|
jezemine
Master Smack Fu Yak Hacker
2886 Posts |
Posted - 2007-10-15 : 18:28:30
|
quote: Originally posted by osirisa I can believe it, 38 people read my sql query problem and ONLY ONE reply to my request for help.Thanks!!!! It's great to know that we help each other in this community.
you are lucky you got even one with that attitude. elsasoft.org |
|
|
khtan
In (Som, Ni, Yak)
17689 Posts |
Posted - 2007-10-15 : 21:41:09
|
quote: Originally posted by osirisa I can believe it, 38 people read my sql query problem and ONLY ONE reply to my request for help.Thanks!!!! It's great to know that we help each other in this community.
You should be grateful. You got the best in SQLTeam to help you. KH[spoiler]Time is always against us[/spoiler] |
|
|
Kristen
Test
22859 Posts |
|
SwePeso
Patron Saint of Lost Yaks
30421 Posts |
Posted - 2007-10-16 : 02:07:16
|
quote: Originally posted by osirisa I can believe it, 38 people read my sql query problem and ONLY ONE reply to my request for help.
More than 38 people stare at my girlfriend every day, I am satisfied they don't do anything more than stare...And about your code. Yikes. Where is your "c"-table for Group_Type column?SELECT sg.Group_Code, sg.Station_Nbr, sg.Beg_Eff_Date, sg.End_Eff_Date, gd.Station_Nbr, COUNT(gd.Station_Nbr) AS ErrorDuplicateFROM TIES_Temp.dbo.Station_Group AS sgINNER JOIN TIES_Temp.dbo.Group_Detail AS gd ON gd.Group_Code = sg.Group_CodeWHERE c.Group_Type = 'NPN'GROUP BY sg.Group_Code, sg.Station_Nbr, sg.Beg_Eff_Date, sg.End_Eff_Date, gd.Station_NbrHAVING COUNT(gd.Station_Nbr) > 1 E 12°55'05.25"N 56°04'39.16" |
|
|
X002548
Not Just a Number
15586 Posts |
|
Kristen
Test
22859 Posts |
Posted - 2007-10-17 : 23:29:31
|
Original posts:10/15/2007 : 16:00:08 Hi:I am a new programmer and very new to SQL2000. I am having huge problems writing stored procedure with multiple cursors. Enclosed you will find the selection Criteria for the first cursor. This criteria is not working I have the following error "ambigouos group_code" Here goes:Select * From(SELECT group_code,station_nbr, beg_eff_date, end_eff_dateFrom TIES_Temp.dbo.station_groupwhere(dateadd(month,-1,getdate()) Between beg_eff_date and end_eff_date))a,(Select station_nbr, count(station_nbr) as ErrorDuplicateFrom TIES_Temp.dbo.station_groupInner Join TIES_Temp.dbo.group_detail on a.group_code = group_codeGROUP BY station_nbrHAVING (COUNT(station_nbr) > 1 )) bWhere a.station_nbr = b.station_nbr and (c.group_type = 'NPN')Thanks for the Help!!! Please respond today 10/15/200710/15/2007 : 17:00:07Thank You Tara, but as you can see I separate both tables with a and b. I have tried to assign "a" before group_code but it doesn't work. Any other suggestion.Please keep in mind that I am new to this world. You have to give me an example of your respond in order for me to understand your idea.Thanks!!!10/15/2007 : 17:04:50 For example ----You mean group_code As Primary. ?10/15/2007 : 17:11:46 If I get rid of the first Select (*)-- This query is a Select within a Select statement I need the first Select to join both queries.---Select * FromSELECT a.group_code,a.station_nbr, a.beg_eff_date, a.end_eff_dateFrom TIES_Temp.dbo.station_group,TIES_Temp.dbo.group_detailwhere(dateadd(month,-1,getdate()) Between beg_eff_date and end_eff_date)and (TIES_Temp.dbo.group_detail.group_type = 'NPN') and(TIES_Temp.dbo.station_group.group_code = TIES_Temp.dbo.group_detail.group_code))a,Select station_nbr, count(station_nbr) as ErrorDuplicateFrom TIES_Temp.dbo.station_groupGROUP BY station_nbrHAVING (COUNT(station_nbr) > 1 ) bWhere a.station_nbr = b.station_nbrHere is the Error Message if I remove the first Select statementServer: Msg 170, Level 15, State 1, Line 5Line 5: Incorrect syntax near ')'.Server: Msg 170, Level 15, State 1, Line 10Line 10: Incorrect syntax near 'b'.10/15/2007 : 17:18:12 Show Profile Email Poster Click to see osirisa's MSN Messenger address Reply with QuoteThanks for the helpGo to Top of PageosirisaStarting MemberUSA21 Posts Posted - 10/15/2007 : 17:59:11 I can believe it, 38 people read my sql query problem and ONLY ONE reply to my request for help.Thanks!!!! It's great to know that we help each other in this community. |
|
|
SwePeso
Patron Saint of Lost Yaks
30421 Posts |
Posted - 2007-10-18 : 01:32:49
|
What happened? E 12°55'05.25"N 56°04'39.16" |
|
|
Kristen
Test
22859 Posts |
Posted - 2007-10-18 : 02:00:20
|
OP deleted original post |
|
|
madhivanan
Premature Yak Congratulator
22864 Posts |
Posted - 2007-10-18 : 05:24:18
|
quote: Originally posted by osirisa Hi:
Why did you remove the question?MadhivananFailing to plan is Planning to fail |
|
|
Next Page
|