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 |
|
koci
Starting Member
6 Posts |
Posted - 2004-10-02 : 18:16:21
|
Hi all. I make one function en SQL Server 2000.---------------------------------------------------------------------------------------CREATE FUNCTION CRelacion (@DesdeFecha Datetime = '01/01/04', @HastaFecha Datetime = '31/12/04') RETURNS TABLEASRETURN (SELECT ALBARANES.IDAlbaran, ALBARANES_DETALLE.IvaVenta FROM ALBARANES INNER JOIN ALBARANES_DETALLE ON ALBARANES.IDAlbaran = ALBARANES_DETALLE.IDAlbaranWHERE ALBARANES.FechaAlbaran Between @DesdeFecha And @HastaFechaGROUP BY ALBARANES.IDAlbaran, ALBARANES_DETALLE.IvaVenta)----------------------------------------------------------------------------------------So my function have to input parameters, @DesdeFecha y @HastaFecha.The question is: for see if work corect, HOW to run this function FROM Query Analizer?When I write in Query Analizer:Exec dbo.CRelacionI obtain the following message (in spanish):"Error en la petición procedimiento 'CRelacion'. 'CRelacion' es un objeto función."I know that it's one function object, but I don't know how to call a such function. When I write:Exec dbo.CRelacion('01/01/04','31/12/04')I got the following message (in spanish):Línea 1: sintaxis incorrecta cerca de '01/01/04'.Have somebody any idea?Thank's anticipated. |
|
|
VIG
Yak Posting Veteran
86 Posts |
Posted - 2004-10-02 : 18:24:03
|
| tryselect * from dbo.CRelacion('01/01/04','31/12/04') |
 |
|
|
koci
Starting Member
6 Posts |
Posted - 2004-10-02 : 18:53:26
|
| Many thank's VIG! It's work!I make this function - like one stored procedure - to call in other procedure. But with this statement (select * from dbo.CRelacion('01/01/04','31/12/04')) how to build the main procedure (the principal)?Main procedure:SELECT CRelacion.IDAlbaran, ALBARAN.FechaAlbaranFROM ALBARANESJOIN ????? ON ALBARAN.IDALBARAN = ????.IDALBARANPS. The main procedure it's a litle more complicated, here I write only one fragment.Thank's. |
 |
|
|
spirit1
Cybernetic Yak Master
11752 Posts |
Posted - 2004-10-02 : 19:00:32
|
will this do?SELECT t2.IDAlbaran, t1.FechaAlbaranFROM ALBARANES t1JOIN dbo.CRelacion('01/01/04','31/12/04') t2 ON t1.IDALBARAN = t2.IDALBARANGo with the flow & have fun! Else fight the flow |
 |
|
|
koci
Starting Member
6 Posts |
Posted - 2004-10-04 : 10:09:21
|
| Thank's spirit1, It's work!How to use one stored procedure (with two input paramaters) instead of this function (dbo.CRelacion), to obtain the same result? The question is: how to use one stored procedure - not user defined function-, (with input parameters) in other procedure? In fact, how to use the columns of one stored procedure in other stored procedure? Something like in Access, when you have one query with parameters in Where statement, can use this query in other query and access the parameterized query's columns like any other column of any other query or table.Thank's anticipated. |
 |
|
|
VIG
Yak Posting Veteran
86 Posts |
Posted - 2004-10-04 : 10:25:55
|
| create proc spCRelacion @DesdeFecha Datetime = '01/01/04', @HastaFecha Datetime = '31/12/04'asset nocount onSELECT t2.IDAlbaran, t1.FechaAlbaranFROM ALBARANES t1JOIN (SELECT ALBARANES.IDAlbaran, ALBARANES_DETALLE.IvaVentaFROM ALBARANES INNER JOIN ALBARANES_DETALLE ON ALBARANES.IDAlbaran = ALBARANES_DETALLE.IDAlbaranWHERE ALBARANES.FechaAlbaran Between @DesdeFecha And @HastaFechaGROUP BY ALBARANES.IDAlbaran, ALBARANES_DETALLE.IvaVenta) as t2ON t1.IDALBARAN = t2.IDALBARANin QAexec spCRelacion @date1,@date2or exec spCRelacion -will be used default parameters |
 |
|
|
spirit1
Cybernetic Yak Master
11752 Posts |
Posted - 2004-10-04 : 10:28:11
|
well sproc's are not designed to work in that way. one way is put the data returned from the sproc in a temp table and then join to the temp table.create table #temp (column definitions)insert into #tempexec YourSProcif you want to execute a 2nd sproc for each row of data thats in the 1st sproc, than you can't. UDF's are designed to do that.but usually that isn't necesarry.maybe if you explained what do you want to do in more detail we can help you better.Go with the flow & have fun! Else fight the flow |
 |
|
|
|
|
|
|
|