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
 SQL

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 Kizer
Microsoft MVP for Windows Server System - SQL Server
http://weblogs.sqlteam.com/tarad/
Go to Top of Page

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!!!
Go to Top of Page

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 Kizer
Microsoft MVP for Windows Server System - SQL Server
http://weblogs.sqlteam.com/tarad/
Go to Top of Page

osirisa
Constraint Violating Yak Guru

289 Posts

Posted - 2007-10-15 : 17:04:50
For example ----You mean group_code As Primary. ?
Go to Top of Page

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 Kizer
Microsoft MVP for Windows Server System - SQL Server
http://weblogs.sqlteam.com/tarad/
Go to Top of Page

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 * From
SELECT a.group_code,a.station_nbr, a.beg_eff_date, a.end_eff_date
From TIES_Temp.dbo.station_group,TIES_Temp.dbo.group_detail
where(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 ErrorDuplicate
From TIES_Temp.dbo.station_group
GROUP BY station_nbr
HAVING (COUNT(station_nbr) > 1 ) b
Where a.station_nbr = b.station_nbr

Here is the Error Message if I remove the first Select statement

Server: Msg 170, Level 15, State 1, Line 5
Line 5: Incorrect syntax near ')'.
Server: Msg 170, Level 15, State 1, Line 10
Line 10: Incorrect syntax near 'b'.



Go to Top of Page

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 Kizer
Microsoft MVP for Windows Server System - SQL Server
http://weblogs.sqlteam.com/tarad/
Go to Top of Page

osirisa
Constraint Violating Yak Guru

289 Posts

Posted - 2007-10-15 : 17:18:12
Thanks for the help
Go to Top of Page

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.
Go to Top of Page

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...
Go to Top of Page

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 Kizer
Microsoft MVP for Windows Server System - SQL Server
http://weblogs.sqlteam.com/tarad/
Go to Top of Page

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
Go to Top of Page

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]

Go to Top of Page

Kristen
Test

22859 Posts

Posted - 2007-10-15 : 22:47:42
Are there any more duplicates to this?, I've just spent time trying to help with:

http://www.sqlteam.com/forums/topic.asp?TOPIC_ID=91025

Kristen
Go to Top of Page

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 ErrorDuplicate
FROM TIES_Temp.dbo.Station_Group AS sg
INNER JOIN TIES_Temp.dbo.Group_Detail AS gd ON gd.Group_Code = sg.Group_Code
WHERE c.Group_Type = 'NPN'
GROUP BY sg.Group_Code,
sg.Station_Nbr,
sg.Beg_Eff_Date,
sg.End_Eff_Date,
gd.Station_Nbr
HAVING COUNT(gd.Station_Nbr) > 1



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

X002548
Not Just a Number

15586 Posts

Posted - 2007-10-16 : 09:35:29
quote:
Originally posted by osirisa

Hi:
I am a new programmer and very new to SQL2000.




And very new to having manners as well?



Brett

8-)

Hint: Want your questions answered fast? Follow the direction in this link
http://weblogs.sqlteam.com/brettk/archive/2005/05/25/5276.aspx

Add yourself!
http://www.frappr.com/sqlteam



Go to Top of Page

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_date
From TIES_Temp.dbo.station_group
where(dateadd(month,-1,getdate()) Between beg_eff_date and end_eff_date))
a,
(Select station_nbr, count(station_nbr) as ErrorDuplicate
From TIES_Temp.dbo.station_group
Inner Join TIES_Temp.dbo.group_detail on a.group_code = group_code
GROUP BY station_nbr
HAVING (COUNT(station_nbr) > 1 )) b
Where a.station_nbr = b.station_nbr and (c.group_type = 'NPN')


Thanks for the Help!!! Please respond today 10/15/2007

10/15/2007 : 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!!!

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 * From
SELECT a.group_code,a.station_nbr, a.beg_eff_date, a.end_eff_date
From TIES_Temp.dbo.station_group,TIES_Temp.dbo.group_detail
where(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 ErrorDuplicate
From TIES_Temp.dbo.station_group
GROUP BY station_nbr
HAVING (COUNT(station_nbr) > 1 ) b
Where a.station_nbr = b.station_nbr

Here is the Error Message if I remove the first Select statement

Server: Msg 170, Level 15, State 1, Line 5
Line 5: Incorrect syntax near ')'.
Server: Msg 170, Level 15, State 1, Line 10
Line 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 Quote
Thanks for the help
Go to Top of Page

osirisa
Starting Member

USA
21 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.
Go to Top of Page

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"
Go to Top of Page

Kristen
Test

22859 Posts

Posted - 2007-10-18 : 02:00:20
OP deleted original post
Go to Top of Page

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?

Madhivanan

Failing to plan is Planning to fail
Go to Top of Page
    Next Page

- Advertisement -