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 |
|
Kristen
Test
22859 Posts |
Posted - 2004-07-22 : 10:17:59
|
I have some code in a function that doesCREATE FUNCTION MyFunction( @foo int)RETURNS varchar(7500)ASRETURN(SELECT MAX(MyColumn)-- Start of Test Execute-- SELECT TOP 10 *FROM MyTable XXXWHERE ... some stuff ... AND NOT EXISTS ( SELECT * FROM MyTable YYY WHERE ... Some Stuff2 ... AND YYY.ID <> XXX.ID )-- End of Test Execute)GO If I highlight the section within the "Test Execute" markers it runs OK. When I try to create the function I getThe column prefix 'XXX' does not match with a table name or alias name used in the query.(The only XXX alias references are in the sub-select)If I comment-out the blue stuff it creates OK.Are sub-selects not allowed in scalar functions?Kristen |
|
|
X002548
Not Just a Number
15586 Posts |
Posted - 2004-07-22 : 14:53:43
|
quote: Originally posted by Kristen Are sub-selects not allowed in scalar functions?
Ummmm.....NoUSE NorthwindGOCREATE FUNCTION udf_myFunction99(@rs int)RETURNS intAS BEGIN DECLARE @x int SELECT @x = (SELECT COUNT(*) FROM Orders o WHERE EXISTS (SELECT * FROM Orders i WHERE o.OrderId = i.OrderId) ) RETURN @x ENDGOSELECT dbo.udf_myFunction99(1)GODROP FUNCTION udf_myFunction99GO Why not post the actual function...and why use a function for this?Brett8-) |
 |
|
|
jsmith8858
Dr. Cross Join
7423 Posts |
Posted - 2004-07-22 : 15:07:49
|
| yes, i agree with Brett, i suspect there is something else in your code that you have not posted that is causing this error.- Jeff |
 |
|
|
Kristen
Test
22859 Posts |
Posted - 2004-07-22 : 16:46:06
|
| OK, that's good to hear, thanks. I changed it to an OUTER JOIN and it worked, but I'll go back and get my Fine Tooth Comb out.Kristen |
 |
|
|
|
|
|