| Author |
Topic |
|
saltwater
Starting Member
4 Posts |
Posted - 2007-05-01 : 00:56:16
|
| Help! Been doing the box step with BOL for several hours , Using tables in Adventureworks to create inline-table-valued function to provide a parameterized view of three JOINS - Have sucessfully created the function but can't figure out where to 'Declare' my variable "@SalesAgentID" need to be able to invoke the function with a particular ID - If you can help me cut this dance short I would REALLY Appreciate it. |
|
|
khtan
In (Som, Ni, Yak)
17689 Posts |
Posted - 2007-05-01 : 00:57:20
|
Please post your code. KH |
 |
|
|
saltwater
Starting Member
4 Posts |
Posted - 2007-05-01 : 01:10:05
|
| Wow I thought I was the only guy awake. Here is the codeUse AdventureworksgoCREATE FUNCTION dbo.udf_SalesInStore2 (@StoreID Int)RETURNS tableASRETURN(SELECT Production.Product.ProductID, Name, Sales.SalesOrderDetail.SalesOrderIDFROM Production.ProductJOIN Sales.SalesOrderDetail ON Production.Product.ProductID = Sales.SalesOrderDetail.ProductIDJOIN Sales.SalesOrderHeaderON Sales.SalesOrderDetail.SalesOrderID = Sales.SalesOrderHeader.SalesOrderIDWHERE CustomerID = @StoreID) |
 |
|
|
khtan
In (Som, Ni, Yak)
17689 Posts |
Posted - 2007-05-01 : 01:19:05
|
"but can't figure out where to 'Declare' my variable "@SalesAgentID" need to be able to invoke the function with a particular ID"You mean how to invoke the function ?declare @SalesAgentID varchar(10)select @SalesAgentID = <somevalue>select *from dbo.udf_SalesInStore2(@SalesAgentID) KH |
 |
|
|
saltwater
Starting Member
4 Posts |
Posted - 2007-05-01 : 01:43:03
|
| KH, Thanks but I had tried that it stills yields all the rowqs in the table it should be less than a dozen. The variable is actually @StoreID instead of @SalesAgent but same princible I want to set @StoreID to 11006 to list that particular stores sales. Sounds easy enough but I have been going in circles with it |
 |
|
|
khtan
In (Som, Ni, Yak)
17689 Posts |
Posted - 2007-05-01 : 02:06:38
|
[code]SELECT Production.Product.ProductID, Name, Sales.SalesOrderDetail.SalesOrderIDFROM Production.ProductJOIN Sales.SalesOrderDetailON Production.Product.ProductID = Sales.SalesOrderDetail.ProductIDJOIN Sales.SalesOrderHeaderON Sales.SalesOrderDetail.SalesOrderID = Sales.SalesOrderHeader.SalesOrderIDWHERE CustomerID = 11006or SELECT *FROM dbo.udf_SalesInStore2(11006)[/code]Both will give 5 rows KH |
 |
|
|
saltwater
Starting Member
4 Posts |
Posted - 2007-05-01 : 02:40:10
|
| KH, THANKS! That works. I know there was supposed to be another soution using a DECLARE but I have two solutions that work so I am going to call it a night. Thanks again for your quick and expert assistance. |
 |
|
|
khtan
In (Som, Ni, Yak)
17689 Posts |
Posted - 2007-05-01 : 02:53:37
|
"I know there was supposed to be another soution using a DECLARE"Sorry, still don't quite understand about your question on the DECLARE part. KH |
 |
|
|
|