Showing posts with label call. Show all posts
Showing posts with label call. Show all posts

Monday, March 12, 2012

how to call webservice from tsql?

Hello!

From an stored proc I want to call an existing web-service.

How to do that?

Must it be done using CLR-procs or is there some way in TSQL?

Greetings

Bjorn

Are you really need this...

CLR is one of the best way to invoke your web service. But i never tested it.

If you use sql server 2000 then the MSXML2.XMLHTTP object & sp_OACreate sp is one of the solution for this requirement.

|||

Here the sample code,

Declare @.Object as Int;

Declare @.ResponseText as Varchar(8000);

Code Snippet

Exec sp_OACreate 'MSXML2.XMLHTTP', @.Object OUT;

Exec sp_OAMethod @.Object, 'open', NULL, 'get',

'http://www.webservicex.com/stockquote.asmx/GetQuote?symbol=MSFT', --Your Web Service Url (invoked)

'false'

Exec sp_OAMethod @.Object, 'send'

Exec sp_OAMethod @.Object, 'responseText', @.ResponseText OUTPUT

Select @.ResponseText

Exec sp_OADestroy @.Object

|||

Hi!

Sorry not writing, that I'm using SS2005...

Makes this some difference?

/Bjorn

|||

The Query (given below) can be used in both versions...

For SQL Server 2005 you have to enable the "OLE Automation" option.

Start-> Programs - > Microsoft SQL Server 2005 -> Configuration Tools ->SQL Server Surface Area Configuration

Click the link Surface Area Configuration for Features

Expand the DB -> Database Engine

Select OLE Automation & Check the checkbox Enable OLE Automation..

After the settings completed execute the code...

|||

Hi!

I have to use post, but how do I get it to work?

I was told I should look at this:

POST /xyzproxy/alarminsert.asmx HTTP/1.1
Host: 192.168.1.111
Content-Type: text/xml; charset=utf-8
Content-Length: length
SOAPAction: "http://tempuri.org/TestWebService"

<?xml version="1.0" encoding="utf-8"?>
<soap:Envelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlnsTongue Tiedoap="http://schemas.xmlsoap.org/soap/envelope/">
<soap:Body>
<TestWebService xmlns="http://tempuri.org/" />
</soap:Body>
</soap:Envelope>

How do I send a request like that using TSQL?

/Bjorn

how to call web service from within Script Component ?

Appreciate if anyone can show me the code to call a web service from Script Component ?

I cannot use the Web Service Task. Because parameters to the webservice are from rows of data inside Data Flow Task.

Thanks !!

Can you not populate a staging table to be used as such:

- After the data flow completes loading a staging table, you'll have an execute SQL task in the control flow to select the data out of that table and store it in an Object variable.
- Use a foreach loop to loop through that object variable, mapping the various columns (if any) to variables
- Inside the foreach loop will be your Web service task. Each time it is called it will use the current value of the parameter variables
- After the foreach loop, you can add another execute SQL task to truncate the staging table if desired.

Does that make sense? At a high level anyway?|||

I think i got what you're saying. However, there is a lot of data. When we go through the data row by row, we take the row data and do 20 different things (update this and that in the database). There is one thing that depends on the output from the webservice.

So, if we use a staging table, memory could become an issue, maybe ? Also, looks like i'll have to to create Data Flow task "twice". The first Data flow task will read the flat file, do some lookup, etc, and put data into a staging table. Then call Web Service Task in the Control Flow. Now that i have the output from the webservice, i need to pass this big object variable back to a Data Flow task for further processing.

I'm just hoping there is a easy way to call the webservice from Script component.... is there a way ?

thanks

|||

mf915 wrote:

Appreciate if anyone can show me the code to call a web service from Script Component ?

I cannot use the Web Service Task. Because parameters to the webservice are from rows of data inside Data Flow Task.

Thanks !!

Hi there,

If you buy Donald Farmer's book (http://www.amazon.com/Rational-Guide-Extending-Script-Guides/dp/1932577254/sr=8-1/qid=1171045629/ref=pd_bbs_sr_1/102-7891523-4086513?ie=UTF8&s=books) there is a downloadable extra chapter that explains EXACTLY how to do this. Many a time I have considered blogging it but that would effectively be plagiarsing Donald's book and I don't want to do that.

-Jamie

|||thanks ! but the book is not available from rationalpress.com until March :(|||

mf915 wrote:

thanks ! but the book is not available from rationalpress.com until March :(

Don't worry. You can get the beta preview version. It contains the same stuff: http://www.amazon.com/Rational-Scripting-Integration-Services-Preview/dp/1932577211/sr=1-2/qid=1171050141/ref=sr_1_2/102-7891523-4086513?ie=UTF8&s=books

-Jamie

|||

Here's one way to use a web service from within an SSIS script component.

1. From the command line, create a wrapper class for the web service using wsdl.exe

wsdl /language:VB http://ws.strikeiron.com/relauto/iplookup?WSDL /out:IPLookup.vb

2. Create an SSIS dataflow, adding in a script component transform.

3. In the script transform, from the Project menu, use "Add Existing Item.." and pull in the wrapper class generated in step 1. You may need to delete the first first few "garbage" characters, which are the Unicode byte order mark.

4. From the Project Menu again, choose Add Reference, and select both the System.Xml and System.Web.Services assemblies.

5. Reference the class from within the transform.

Imports System

Imports System.Data

Imports System.Math

Imports Microsoft.SqlServer.Dts.Pipeline.Wrapper

Imports Microsoft.SqlServer.Dts.Runtime.Wrapper

Public Class ScriptMain

Inherits UserComponent

Private ws As DNS = New DNS()

' Wrapper for web service

Private dnsInfo As DNSInfo

' wrapper for Response from web service

Public Overrides Sub Input0_ProcessInputRow(ByVal Row As Input0Buffer)

Try

Dim server As String = Row.ServerName

dnsInfo = ws.DNSLookup(server)

ComponentMetaData.FireInformation(0, ComponentMetaData.Name, _

String.Format(" {0} maps to IPv4 {1}", server, dnsInfo.AddressList(0)), _

String.Empty, 0, True)

Catch ex As Exception

ComponentMetaData.FireError(1, ComponentMetaData.Name, _

ex.Message, String.Empty, 0, True)

End Try

End Sub

End Class

|||

Spot on as usual jaegd. This is how Donald describes doing it.

-Jamie

|||

Well, I've been able to sucessfully connect to a web service (in my case a Sharepoint List) in the script component using the method described above, and now things are starting to get messy. I'm wondering if anyone has any advice or a "best practice suggestion" for the following scenario, where I'm taking the XML response of a web service and pushing into the data flow using the "XML Source" component:

1. In the script component, query a web service and get the XML response.

1b. Remove multiple namespaces from the XML response using XSLT, since the XML Source component can't handle them.

2. Get the schema of the web service response using the DataSet class/GetXMLSchema method.

3. Push the XML response data into a variable to be read by the "XML Source" component in the dataflow.

4. Write the inferred XML schema to a file. The file name is set using the System::ExecutionInstanceGUID, which ensures a unique file name linked to the particular package execution.

5. Open up the expressions for the data flow task, and set the XMLSchemaDefinition property for the XML Soruce Component to point to the schema file just written. Because this does file not exist at validation time, the data flow task property DelayValidation must be set to True.

Of course, it would be impossible to even create a data flow without having some sort of "starting point" schema to work with. I'm just trying to construct some sort of framework so I can add or remove an item from the Sharepoint List I'm accessing using via Web Service and it doesn't cause my package to fail all over the place because the schema doesn't exactly match the data.

With this (or perhaps a simpler, easier approach?) the dynamically generated schema can change as I make small changes to my sharepoint lists. I'm wondering if I'm making this too complicated, or if it would just be easier to have a maually-maintained repository of XML schemas somewhere in the filesystem.

|||I would just maintain your own XML schemas, and pass the values in through configurations. I'm not sure if there is a simpler or easier approach to a package that has a dynamic schema. Your destinations will have problems with flucuating schemas as well....and from a brief search on the forum building a package dynamically at runtime may be your only option.

how to call web service from within Script Component ?

Appreciate if anyone can show me the code to call a web service from Script Component ?

I cannot use the Web Service Task. Because parameters to the webservice are from rows of data inside Data Flow Task.

Thanks !!

Can you not populate a staging table to be used as such:

- After the data flow completes loading a staging table, you'll have an execute SQL task in the control flow to select the data out of that table and store it in an Object variable.
- Use a foreach loop to loop through that object variable, mapping the various columns (if any) to variables
- Inside the foreach loop will be your Web service task. Each time it is called it will use the current value of the parameter variables
- After the foreach loop, you can add another execute SQL task to truncate the staging table if desired.

Does that make sense? At a high level anyway?|||

I think i got what you're saying. However, there is a lot of data. When we go through the data row by row, we take the row data and do 20 different things (update this and that in the database). There is one thing that depends on the output from the webservice.

So, if we use a staging table, memory could become an issue, maybe ? Also, looks like i'll have to to create Data Flow task "twice". The first Data flow task will read the flat file, do some lookup, etc, and put data into a staging table. Then call Web Service Task in the Control Flow. Now that i have the output from the webservice, i need to pass this big object variable back to a Data Flow task for further processing.

I'm just hoping there is a easy way to call the webservice from Script component.... is there a way ?

thanks

|||

mf915 wrote:

Appreciate if anyone can show me the code to call a web service from Script Component ?

I cannot use the Web Service Task. Because parameters to the webservice are from rows of data inside Data Flow Task.

Thanks !!

Hi there,

If you buy Donald Farmer's book (http://www.amazon.com/Rational-Guide-Extending-Script-Guides/dp/1932577254/sr=8-1/qid=1171045629/ref=pd_bbs_sr_1/102-7891523-4086513?ie=UTF8&s=books) there is a downloadable extra chapter that explains EXACTLY how to do this. Many a time I have considered blogging it but that would effectively be plagiarsing Donald's book and I don't want to do that.

-Jamie

|||thanks ! but the book is not available from rationalpress.com until March :(|||

mf915 wrote:

thanks ! but the book is not available from rationalpress.com until March :(

Don't worry. You can get the beta preview version. It contains the same stuff: http://www.amazon.com/Rational-Scripting-Integration-Services-Preview/dp/1932577211/sr=1-2/qid=1171050141/ref=sr_1_2/102-7891523-4086513?ie=UTF8&s=books

-Jamie

|||

Here's one way to use a web service from within an SSIS script component.

1. From the command line, create a wrapper class for the web service using wsdl.exe

wsdl /language:VB http://ws.strikeiron.com/relauto/iplookup?WSDL /out:IPLookup.vb

2. Create an SSIS dataflow, adding in a script component transform.

3. In the script transform, from the Project menu, use "Add Existing Item.." and pull in the wrapper class generated in step 1. You may need to delete the first first few "garbage" characters, which are the Unicode byte order mark.

4. From the Project Menu again, choose Add Reference, and select both the System.Xml and System.Web.Services assemblies.

5. Reference the class from within the transform.

Imports System

Imports System.Data

Imports System.Math

Imports Microsoft.SqlServer.Dts.Pipeline.Wrapper

Imports Microsoft.SqlServer.Dts.Runtime.Wrapper

Public Class ScriptMain

Inherits UserComponent

Private ws As DNS = New DNS()

' Wrapper for web service

Private dnsInfo As DNSInfo

' wrapper for Response from web service

Public Overrides Sub Input0_ProcessInputRow(ByVal Row As Input0Buffer)

Try

Dim server As String = Row.ServerName

dnsInfo = ws.DNSLookup(server)

ComponentMetaData.FireInformation(0, ComponentMetaData.Name, _

String.Format(" {0} maps to IPv4 {1}", server, dnsInfo.AddressList(0)), _

String.Empty, 0, True)

Catch ex As Exception

ComponentMetaData.FireError(1, ComponentMetaData.Name, _

ex.Message, String.Empty, 0, True)

End Try

End Sub

End Class

|||

Spot on as usual jaegd. This is how Donald describes doing it.

-Jamie

|||

Well, I've been able to sucessfully connect to a web service (in my case a Sharepoint List) in the script component using the method described above, and now things are starting to get messy. I'm wondering if anyone has any advice or a "best practice suggestion" for the following scenario, where I'm taking the XML response of a web service and pushing into the data flow using the "XML Source" component:

1. In the script component, query a web service and get the XML response.

1b. Remove multiple namespaces from the XML response using XSLT, since the XML Source component can't handle them.

2. Get the schema of the web service response using the DataSet class/GetXMLSchema method.

3. Push the XML response data into a variable to be read by the "XML Source" component in the dataflow.

4. Write the inferred XML schema to a file. The file name is set using the System::ExecutionInstanceGUID, which ensures a unique file name linked to the particular package execution.

5. Open up the expressions for the data flow task, and set the XMLSchemaDefinition property for the XML Soruce Component to point to the schema file just written. Because this does file not exist at validation time, the data flow task property DelayValidation must be set to True.

Of course, it would be impossible to even create a data flow without having some sort of "starting point" schema to work with. I'm just trying to construct some sort of framework so I can add or remove an item from the Sharepoint List I'm accessing using via Web Service and it doesn't cause my package to fail all over the place because the schema doesn't exactly match the data.

With this (or perhaps a simpler, easier approach?) the dynamically generated schema can change as I make small changes to my sharepoint lists. I'm wondering if I'm making this too complicated, or if it would just be easier to have a maually-maintained repository of XML schemas somewhere in the filesystem.

|||I would just maintain your own XML schemas, and pass the values in through configurations. I'm not sure if there is a simpler or easier approach to a package that has a dynamic schema. Your destinations will have problems with flucuating schemas as well....and from a brief search on the forum building a package dynamically at runtime may be your only option.

How to 'call' UDFs from SPs

New to SQL Server in general (2000 in particular) and working through the
relative difficulty of upsizing an Access '03 database that's currently
used in a small ASP web application. The database is generally hit via the
ADO command object, passing parameters as needed via CommandText.
Could someone show an example or two of how to 'call' a user-defined
function (with one parameter) from a stored procedure (also with one input
parameter, the same parameter that's used in the function), where the
procedure relies on a value returned by the function?
Please excuse if this is entirely too unclear, or is posted to the wrong
section. Thanks.
Message posted via http://www.sqlmonster.com
Without knowing exactly what you're trying to do, you would call a UDF that
returns an integer as follows:
DECLARE @.i INTEGER
SET @.i = dbo.udfname(parameter)
Your stored procedure could make this call and use the variable @.i in
whatever fashion it needs. Not sure entirely what you're trying to do, or
how you're trying to do it, or the types you're dealing with, but that's the
basics of it.
Now if you're talking about the mechanics of the call from the ASP web app
side, we need to look at other stuff.
"The Gekkster via SQLMonster.com" <forum@.SQLMonster.com> wrote in message
news:17b4719d63284899b65bdc6083ed0ef8@.SQLMonster.c om...
> New to SQL Server in general (2000 in particular) and working through the
> relative difficulty of upsizing an Access '03 database that's currently
> used in a small ASP web application. The database is generally hit via the
> ADO command object, passing parameters as needed via CommandText.
> Could someone show an example or two of how to 'call' a user-defined
> function (with one parameter) from a stored procedure (also with one input
> parameter, the same parameter that's used in the function), where the
> procedure relies on a value returned by the function?
> Please excuse if this is entirely too unclear, or is posted to the wrong
> section. Thanks.
> --
> Message posted via http://www.sqlmonster.com
|||For stored procedures, it is not "necessary," although preferable, to
qualify the object with the owner. For UDFs, however, this is mandatory:
<owner/schema>.<UDF name><parameter list>
SET @.var = dbo.udfname(@.parm1, @.parm2, ..., @.parmn)
Sincerely,
Anthony Thomas

"Michael C#" <xyz@.abcdef.com> wrote in message
news:h2K0e.402$CN3.123@.fe11.lga...
Without knowing exactly what you're trying to do, you would call a UDF that
returns an integer as follows:
DECLARE @.i INTEGER
SET @.i = dbo.udfname(parameter)
Your stored procedure could make this call and use the variable @.i in
whatever fashion it needs. Not sure entirely what you're trying to do, or
how you're trying to do it, or the types you're dealing with, but that's the
basics of it.
Now if you're talking about the mechanics of the call from the ASP web app
side, we need to look at other stuff.
"The Gekkster via SQLMonster.com" <forum@.SQLMonster.com> wrote in message
news:17b4719d63284899b65bdc6083ed0ef8@.SQLMonster.c om...
> New to SQL Server in general (2000 in particular) and working through the
> relative difficulty of upsizing an Access '03 database that's currently
> used in a small ASP web application. The database is generally hit via the
> ADO command object, passing parameters as needed via CommandText.
> Could someone show an example or two of how to 'call' a user-defined
> function (with one parameter) from a stored procedure (also with one input
> parameter, the same parameter that's used in the function), where the
> procedure relies on a value returned by the function?
> Please excuse if this is entirely too unclear, or is posted to the wrong
> section. Thanks.
> --
> Message posted via http://www.sqlmonster.com
|||> "Michael C#" <xyz@.abcdef.com> wrote in message
> news:h2K0e.402$CN3.123@.fe11.lga...
...
> SET @.i = dbo.udfname(parameter)
|||Thanks, guys.
I was trying to do something like this, although UDFs and SPs are new to me
and I'm obviously missing something here:
*******
CREATE PROCEDURE dbo.usp_My_Procedure
(
DECLARE @.CountOfWidgets INTEGER
SET @.CountOfWidgets = dbo.udf_My_Function(@.B)
)
AS
DECLARE @.B varchar(255)
SELECT COUNT(CountOfWidgets ) AS CountOfCountOfWidgets,
CountOfCountOfWidgets / CountOfWidgets AS Expr2
FROM dbo.udf_My_Function(@.B) CROSS JOIN
dbo.some_other_***
dbo.some_other_***
WHERE dbo.udf_My_Function(@.B)) AND some_other_criteria_***
GROUP BY CountOfWidgets, something_here_***
*******
In this scenario, @.B is a parameter that is passed (or needs to be passed)
from the ASP script to the procedure, like this:
*******
objCommand.CommandText = "usp_My_Procedure '" & objRS("WidgetBrand") & "'"
objCommand.CommandType = adCmdStoredProc
set objRS = objCommand.Execute
*******
The ASP part has been working fine when using Access; I'm just not yet up
to speed with procedures and functions for SQL Server.
Ideas...?
Message posted via http://www.sqlmonster.com
|||I think I see some potential "issues" in your SELECT statement already (I'm
assuming the ***'s are actually just where you blanked out the names for our
benefit of course). It would definitely help narrow down the problem if you
could post DDL, sample data and expected results. Your UDF code would help
troubleshoot it also.
You can try running your usp_My_Procedure in QA to see if it actually works
the way you expect it to also, or to see what error it returns if not.
Thanks
"The Gekkster via SQLMonster.com" <forum@.SQLMonster.com> wrote in message
news:316caf07f5ff49419d92cc87abdd0b7e@.SQLMonster.c om...
> Thanks, guys.
> I was trying to do something like this, although UDFs and SPs are new to
> me
> and I'm obviously missing something here:
> *******
> CREATE PROCEDURE dbo.usp_My_Procedure
> (
> DECLARE @.CountOfWidgets INTEGER
> SET @.CountOfWidgets = dbo.udf_My_Function(@.B)
> )
> AS
> DECLARE @.B varchar(255)
> SELECT COUNT(CountOfWidgets ) AS CountOfCountOfWidgets,
> CountOfCountOfWidgets / CountOfWidgets AS Expr2
> FROM dbo.udf_My_Function(@.B) CROSS JOIN
> dbo.some_other_***
> dbo.some_other_***
> WHERE dbo.udf_My_Function(@.B)) AND some_other_criteria_***
> GROUP BY CountOfWidgets, something_here_***
> *******
> In this scenario, @.B is a parameter that is passed (or needs to be passed)
> from the ASP script to the procedure, like this:
> *******
> objCommand.CommandText = "usp_My_Procedure '" & objRS("WidgetBrand") & "'"
> objCommand.CommandType = adCmdStoredProc
> set objRS = objCommand.Execute
> *******
> The ASP part has been working fine when using Access; I'm just not yet up
> to speed with procedures and functions for SQL Server.
> Ideas...?
> --
> Message posted via http://www.sqlmonster.com
|||Here is the (upsized) UDF:
*****
ALTER FUNCTION dbo.udf_EDB_Current_Inventory
(@.B varchar(255))
RETURNS TABLE
AS
RETURN ( SELECT COUNT(dbo.tblUnits.UnitInDatabase) AS
CountOfUnitInDatabase
FROM dbo.SQUISH_V2 CROSS JOIN
dbo.tblRetailers CROSS JOIN
dbo.tblUnits
WHERE (dbo.SQUISH_V2.CLASS_TYPE = @.B)
GROUP BY dbo.tblUnits.CurrentlyInStock, dbo.tblRetailers.Active
HAVING (dbo.tblUnits.CurrentlyInStock = 1) AND
(dbo.tblRetailers.Active = 1) )
*****
And this is the (upsized) SQL statement that needs to be incorporated into
the procedure, at least as 'determined/attempted' in the temporary Access
project (the cross joins are also courtesy of upsizing, and I'll need to
sort those out as well):
*****
SELECT COUNT(udf_EDB_Current_Inventory.CountOfUnitInDatab ase) AS
CountOfCountOfUnitInDatabase,
CountOfCountOfUnitInDatabase /
udf_EDB_Current_Inventory.CountOfUnitInDatabase AS Expr2
FROM dbo.udf_EDB_Current_Inventory() udf_EDB_Current_Inventory
CROSS JOIN
dbo.SQUISH_V2 CROSS JOIN
dbo.tblRetailers CROSS JOIN
dbo.tblUnits
WHERE (dbo.SQUISH_V2.CLASS_TYPE = @.B) AND (DATEDIFF(d,
dbo.tblUnits.AddedToInventory, GETDATE()) > 30) AND (DATEDIFF(d,
dbo.tblUnits.AddedToInventory, GETDATE()) <= 60)
GROUP BY udf_EDB_Current_Inventory.CountOfUnitInDatabase,
dbo.tblUnits.CurrentlyInStock, dbo.tblRetailers.Active
HAVING (dbo.tblUnits.CurrentlyInStock = 1) AND
(dbo.tblRetailers.Active = 1)
*****
In trying to save/create the procedure I get the following error: "ADO
error: An insufficient number of arguments were supplied for the procedure
or function dbo.udf_EDB_Current_Inventory."
I'm not familiar enough with this, other than the error message is telling
me that either (i) the needed input parameter is not being passed; or (ii)
the function needs to include an output parameter to send back to the
procedure that's calling it?
Prior to this attempt to upsize, all data resided in SQL tables, and
queries were in Access (linked SQL tables). My hope was just to initially
move the queries into SQL Server and to take Access out of the picture. Too
bad I can't just use views with parameters, and worry about the greater
benefit of UDFs and SPs later. Or is that somehow possible...?
Message posted via http://www.sqlmonster.com
|||Sorry, Mike; I wasn't trying to correct what you said, but clarify a general
error most users have when they first start writing these. You had the
information there, but sometimes they need it spelled out.
Sincerely,
Anthony Thomas

"Michael C#" <xyz@.abcdef.com> wrote in message
news:UVL0e.8937$Qi6.1322@.fe09.lga...
> "Michael C#" <xyz@.abcdef.com> wrote in message
> news:h2K0e.402$CN3.123@.fe11.lga...
...
> SET @.i = dbo.udfname(parameter)
|||On Fri, 25 Mar 2005 06:20:16 GMT, The Gekkster via SQLMonster.com wrote:
(snip)
>In trying to save/create the procedure I get the following error: "ADO
>error: An insufficient number of arguments were supplied for the procedure
>or function dbo.udf_EDB_Current_Inventory."
Hi Gekkster,
From this part of the code you posted:

>ALTER FUNCTION dbo.udf_EDB_Current_Inventory
>(@.B varchar(255))
>RETURNS TABLE
I see that your user-defined function requires one argument.
In the stored procedure where you call the function, the call looks like
this:

>FROM dbo.udf_EDB_Current_Inventory() udf_EDB_Current_Inventory
And between the parentheses, there is no argument. The error message is
right: an insufficient number of arguments were supplied. Since I have
no idea what you are trying to accomplish, I can't give any suggestions
WHAT to put between the parentheses, but you better put SOMETHING there!
Oh, by the way:

>SELECT COUNT(udf_EDB_Current_Inventory.CountOfUnitInDatab ase) AS
>CountOfCountOfUnitInDatabase,
> CountOfCountOfUnitInDatabase /
>udf_EDB_Current_Inventory.CountOfUnitInDatabase AS Expr2
is illegal in SQL Server. The whole SELECT statement is executed at
once; the alias CountOfCountOfUnitInDatabase can't be used in other
parts of the SELECT clause. The only place in a query where a column
alias can be used in in the ORDER BY clause.
The workaround is to either repeat the expression, or use a derived
table.
Best, Hugo
(Remove _NO_ and _SPAM_ to get my e-mail address)
|||Hi Hugo,
Thanks for the input. I've tried to rework this a bit, and now have the
following view and function (I've dropped some of the WHEREs for now to
help sort this out):
*******
SELECT dbo.tblUnits.UnitInDatabase, dbo.tblRetailers.Active,
dbo.tblUnits.CurrentlyInStock, dbo.SQUISH_V2.CLASS_TYPE,
dbo.Units.AddedToInventory, dbo.tblRetailers.Name
FROM dbo.SQUISH_V2 INNER JOIN
dbo.tblUnits ON dbo.SQUISH_V2.UnitID =
dbo.tblUnits.UnitID INNER JOIN
dbo.tblRetailers ON dbo.tblRetailers.RetailerID =
dbo.tblUnits.RetailerID
*******
*******
ALTER FUNCTION dbo.udf_EDB_Current_Inventory (
@.ClassTypeRequested varchar(255))
RETURNS TABLE
AS
RETURN (SELECT COUNT(UnitInDatabase) AS CountOfUnitInDatabase
FROM vw_EDB_Current_InventoryView
WHERE CLASS_TYPE = @.ClassTypeRequested
AND Active = 1
AND CurrentlyInStock = 1)
*******
So I can now retrieve the needed count via the function, which is properly
'restrictive' based on the WHERE clause it contains. When I test this in
SQL Server QA I get the correct result, like so:
DECLARE @.B varchar(255)
SET @.B = 'Custom'
SELECT *
FROM dbo.udf_EDB_Current_Inventory(@.B)
So my question now is this: To minimize (or hopefully avoid) having to
recode the ASP I'm using, is there a way to do this via a stored procedure
(or even the above function) so that I can continue to make the call like
this:
*******
objCommand1.CommandText = "usp_My_Procedure '" & objRS("SomeID") & "'"
objCommand1.CommandType = adCmdStoredProc
set objRS1 = objCommand1.Execute
*******
This part is still giving me some difficulty, as I don't seem to be getting
the 'parameter' passed properly as was the case with using Access.
Sorry for being so slow to get this - I can only plead ignorance from being
new to UDFs and SPs. Thanks.
Message posted via http://www.sqlmonster.com

How to 'call' UDFs from SPs

New to SQL Server in general (2000 in particular) and working through the
relative difficulty of upsizing an Access '03 database that's currently
used in a small ASP web application. The database is generally hit via the
ADO command object, passing parameters as needed via CommandText.
Could someone show an example or two of how to 'call' a user-defined
function (with one parameter) from a stored procedure (also with one input
parameter, the same parameter that's used in the function), where the
procedure relies on a value returned by the function?
Please excuse if this is entirely too unclear, or is posted to the wrong
section. Thanks.
--
Message posted via http://www.sqlmonster.comWithout knowing exactly what you're trying to do, you would call a UDF that
returns an integer as follows:
DECLARE @.i INTEGER
SET @.i = dbo.udfname(parameter)
Your stored procedure could make this call and use the variable @.i in
whatever fashion it needs. Not sure entirely what you're trying to do, or
how you're trying to do it, or the types you're dealing with, but that's the
basics of it.
Now if you're talking about the mechanics of the call from the ASP web app
side, we need to look at other stuff.
"The Gekkster via SQLMonster.com" <forum@.SQLMonster.com> wrote in message
news:17b4719d63284899b65bdc6083ed0ef8@.SQLMonster.com...
> New to SQL Server in general (2000 in particular) and working through the
> relative difficulty of upsizing an Access '03 database that's currently
> used in a small ASP web application. The database is generally hit via the
> ADO command object, passing parameters as needed via CommandText.
> Could someone show an example or two of how to 'call' a user-defined
> function (with one parameter) from a stored procedure (also with one input
> parameter, the same parameter that's used in the function), where the
> procedure relies on a value returned by the function?
> Please excuse if this is entirely too unclear, or is posted to the wrong
> section. Thanks.
> --
> Message posted via http://www.sqlmonster.com|||For stored procedures, it is not "necessary," although preferable, to
qualify the object with the owner. For UDFs, however, this is mandatory:
<owner/schema>.<UDF name><parameter list>
SET @.var = dbo.udfname(@.parm1, @.parm2, ..., @.parmn)
Sincerely,
Anthony Thomas
"Michael C#" <xyz@.abcdef.com> wrote in message
news:h2K0e.402$CN3.123@.fe11.lga...
Without knowing exactly what you're trying to do, you would call a UDF that
returns an integer as follows:
DECLARE @.i INTEGER
SET @.i = dbo.udfname(parameter)
Your stored procedure could make this call and use the variable @.i in
whatever fashion it needs. Not sure entirely what you're trying to do, or
how you're trying to do it, or the types you're dealing with, but that's the
basics of it.
Now if you're talking about the mechanics of the call from the ASP web app
side, we need to look at other stuff.
"The Gekkster via SQLMonster.com" <forum@.SQLMonster.com> wrote in message
news:17b4719d63284899b65bdc6083ed0ef8@.SQLMonster.com...
> New to SQL Server in general (2000 in particular) and working through the
> relative difficulty of upsizing an Access '03 database that's currently
> used in a small ASP web application. The database is generally hit via the
> ADO command object, passing parameters as needed via CommandText.
> Could someone show an example or two of how to 'call' a user-defined
> function (with one parameter) from a stored procedure (also with one input
> parameter, the same parameter that's used in the function), where the
> procedure relies on a value returned by the function?
> Please excuse if this is entirely too unclear, or is posted to the wrong
> section. Thanks.
> --
> Message posted via http://www.sqlmonster.com|||> "Michael C#" <xyz@.abcdef.com> wrote in message
> news:h2K0e.402$CN3.123@.fe11.lga...
...
> SET @.i = dbo.udfname(parameter)|||Thanks, guys.
I was trying to do something like this, although UDFs and SPs are new to me
and I'm obviously missing something here:
*******
CREATE PROCEDURE dbo.usp_My_Procedure
(
DECLARE @.CountOfWidgets INTEGER
SET @.CountOfWidgets = dbo.udf_My_Function(@.B)
)
AS
DECLARE @.B varchar(255)
SELECT COUNT(CountOfWidgets ) AS CountOfCountOfWidgets,
CountOfCountOfWidgets / CountOfWidgets AS Expr2
FROM dbo.udf_My_Function(@.B) CROSS JOIN
dbo.some_other_***
dbo.some_other_***
WHERE dbo.udf_My_Function(@.B)) AND some_other_criteria_***
GROUP BY CountOfWidgets, something_here_***
*******
In this scenario, @.B is a parameter that is passed (or needs to be passed)
from the ASP script to the procedure, like this:
*******
objCommand.CommandText = "usp_My_Procedure '" & objRS("WidgetBrand") & "'"
objCommand.CommandType = adCmdStoredProc
set objRS = objCommand.Execute
*******
The ASP part has been working fine when using Access; I'm just not yet up
to speed with procedures and functions for SQL Server.
Ideas...?
--
Message posted via http://www.sqlmonster.com|||I think I see some potential "issues" in your SELECT statement already (I'm
assuming the ***'s are actually just where you blanked out the names for our
benefit of course). It would definitely help narrow down the problem if you
could post DDL, sample data and expected results. Your UDF code would help
troubleshoot it also.
You can try running your usp_My_Procedure in QA to see if it actually works
the way you expect it to also, or to see what error it returns if not.
Thanks
"The Gekkster via SQLMonster.com" <forum@.SQLMonster.com> wrote in message
news:316caf07f5ff49419d92cc87abdd0b7e@.SQLMonster.com...
> Thanks, guys.
> I was trying to do something like this, although UDFs and SPs are new to
> me
> and I'm obviously missing something here:
> *******
> CREATE PROCEDURE dbo.usp_My_Procedure
> (
> DECLARE @.CountOfWidgets INTEGER
> SET @.CountOfWidgets = dbo.udf_My_Function(@.B)
> )
> AS
> DECLARE @.B varchar(255)
> SELECT COUNT(CountOfWidgets ) AS CountOfCountOfWidgets,
> CountOfCountOfWidgets / CountOfWidgets AS Expr2
> FROM dbo.udf_My_Function(@.B) CROSS JOIN
> dbo.some_other_***
> dbo.some_other_***
> WHERE dbo.udf_My_Function(@.B)) AND some_other_criteria_***
> GROUP BY CountOfWidgets, something_here_***
> *******
> In this scenario, @.B is a parameter that is passed (or needs to be passed)
> from the ASP script to the procedure, like this:
> *******
> objCommand.CommandText = "usp_My_Procedure '" & objRS("WidgetBrand") & "'"
> objCommand.CommandType = adCmdStoredProc
> set objRS = objCommand.Execute
> *******
> The ASP part has been working fine when using Access; I'm just not yet up
> to speed with procedures and functions for SQL Server.
> Ideas...?
> --
> Message posted via http://www.sqlmonster.com|||Here is the (upsized) UDF:
*****
ALTER FUNCTION dbo.udf_EDB_Current_Inventory
(@.B varchar(255))
RETURNS TABLE
AS
RETURN ( SELECT COUNT(dbo.tblUnits.UnitInDatabase) AS
CountOfUnitInDatabase
FROM dbo.SQUISH_V2 CROSS JOIN
dbo.tblRetailers CROSS JOIN
dbo.tblUnits
WHERE (dbo.SQUISH_V2.CLASS_TYPE = @.B)
GROUP BY dbo.tblUnits.CurrentlyInStock, dbo.tblRetailers.Active
HAVING (dbo.tblUnits.CurrentlyInStock = 1) AND
(dbo.tblRetailers.Active = 1) )
*****
And this is the (upsized) SQL statement that needs to be incorporated into
the procedure, at least as 'determined/attempted' in the temporary Access
project (the cross joins are also courtesy of upsizing, and I'll need to
sort those out as well):
*****
SELECT COUNT(udf_EDB_Current_Inventory.CountOfUnitInDatabase) AS
CountOfCountOfUnitInDatabase,
CountOfCountOfUnitInDatabase /
udf_EDB_Current_Inventory.CountOfUnitInDatabase AS Expr2
FROM dbo.udf_EDB_Current_Inventory() udf_EDB_Current_Inventory
CROSS JOIN
dbo.SQUISH_V2 CROSS JOIN
dbo.tblRetailers CROSS JOIN
dbo.tblUnits
WHERE (dbo.SQUISH_V2.CLASS_TYPE = @.B) AND (DATEDIFF(d,
dbo.tblUnits.AddedToInventory, GETDATE()) > 30) AND (DATEDIFF(d,
dbo.tblUnits.AddedToInventory, GETDATE()) <= 60)
GROUP BY udf_EDB_Current_Inventory.CountOfUnitInDatabase,
dbo.tblUnits.CurrentlyInStock, dbo.tblRetailers.Active
HAVING (dbo.tblUnits.CurrentlyInStock = 1) AND
(dbo.tblRetailers.Active = 1)
*****
In trying to save/create the procedure I get the following error: "ADO
error: An insufficient number of arguments were supplied for the procedure
or function dbo.udf_EDB_Current_Inventory."
I'm not familiar enough with this, other than the error message is telling
me that either (i) the needed input parameter is not being passed; or (ii)
the function needs to include an output parameter to send back to the
procedure that's calling it?
Prior to this attempt to upsize, all data resided in SQL tables, and
queries were in Access (linked SQL tables). My hope was just to initially
move the queries into SQL Server and to take Access out of the picture. Too
bad I can't just use views with parameters, and worry about the greater
benefit of UDFs and SPs later. Or is that somehow possible...?
--
Message posted via http://www.sqlmonster.com|||Sorry, Mike; I wasn't trying to correct what you said, but clarify a general
error most users have when they first start writing these. You had the
information there, but sometimes they need it spelled out.
Sincerely,
Anthony Thomas
"Michael C#" <xyz@.abcdef.com> wrote in message
news:UVL0e.8937$Qi6.1322@.fe09.lga...
> "Michael C#" <xyz@.abcdef.com> wrote in message
> news:h2K0e.402$CN3.123@.fe11.lga...
...
> SET @.i = dbo.udfname(parameter)|||On Fri, 25 Mar 2005 06:20:16 GMT, The Gekkster via SQLMonster.com wrote:
(snip)
>In trying to save/create the procedure I get the following error: "ADO
>error: An insufficient number of arguments were supplied for the procedure
>or function dbo.udf_EDB_Current_Inventory."
Hi Gekkster,
From this part of the code you posted:
>ALTER FUNCTION dbo.udf_EDB_Current_Inventory
>(@.B varchar(255))
>RETURNS TABLE
I see that your user-defined function requires one argument.
In the stored procedure where you call the function, the call looks like
this:
>FROM dbo.udf_EDB_Current_Inventory() udf_EDB_Current_Inventory
And between the parentheses, there is no argument. The error message is
right: an insufficient number of arguments were supplied. Since I have
no idea what you are trying to accomplish, I can't give any suggestions
WHAT to put between the parentheses, but you better put SOMETHING there!
Oh, by the way:
>SELECT COUNT(udf_EDB_Current_Inventory.CountOfUnitInDatabase) AS
>CountOfCountOfUnitInDatabase,
> CountOfCountOfUnitInDatabase /
>udf_EDB_Current_Inventory.CountOfUnitInDatabase AS Expr2
is illegal in SQL Server. The whole SELECT statement is executed at
once; the alias CountOfCountOfUnitInDatabase can't be used in other
parts of the SELECT clause. The only place in a query where a column
alias can be used in in the ORDER BY clause.
The workaround is to either repeat the expression, or use a derived
table.
Best, Hugo
--
(Remove _NO_ and _SPAM_ to get my e-mail address)|||Hi Hugo,
Thanks for the input. I've tried to rework this a bit, and now have the
following view and function (I've dropped some of the WHEREs for now to
help sort this out):
*******
SELECT dbo.tblUnits.UnitInDatabase, dbo.tblRetailers.Active,
dbo.tblUnits.CurrentlyInStock, dbo.SQUISH_V2.CLASS_TYPE,
dbo.Units.AddedToInventory, dbo.tblRetailers.Name
FROM dbo.SQUISH_V2 INNER JOIN
dbo.tblUnits ON dbo.SQUISH_V2.UnitID =dbo.tblUnits.UnitID INNER JOIN
dbo.tblRetailers ON dbo.tblRetailers.RetailerID =dbo.tblUnits.RetailerID
*******
*******
ALTER FUNCTION dbo.udf_EDB_Current_Inventory (
@.ClassTypeRequested varchar(255))
RETURNS TABLE
AS
RETURN (SELECT COUNT(UnitInDatabase) AS CountOfUnitInDatabase
FROM vw_EDB_Current_InventoryView
WHERE CLASS_TYPE = @.ClassTypeRequested
AND Active = 1
AND CurrentlyInStock = 1)
*******
So I can now retrieve the needed count via the function, which is properly
'restrictive' based on the WHERE clause it contains. When I test this in
SQL Server QA I get the correct result, like so:
DECLARE @.B varchar(255)
SET @.B = 'Custom'
SELECT *
FROM dbo.udf_EDB_Current_Inventory(@.B)
So my question now is this: To minimize (or hopefully avoid) having to
recode the ASP I'm using, is there a way to do this via a stored procedure
(or even the above function) so that I can continue to make the call like
this:
*******
objCommand1.CommandText = "usp_My_Procedure '" & objRS("SomeID") & "'"
objCommand1.CommandType = adCmdStoredProc
set objRS1 = objCommand1.Execute
*******
This part is still giving me some difficulty, as I don't seem to be getting
the 'parameter' passed properly as was the case with using Access.
Sorry for being so slow to get this - I can only plead ignorance from being
new to UDFs and SPs. Thanks.
--
Message posted via http://www.sqlmonster.com|||CREATE PROCEDURE dbo.usp_My_Procedure @.SomeID VARCHAR(255) AS
SELECT *
FROM dbo.udf_EDB_Current_Inventory(@.SomeID)
GO
Run that in QA in your database. It will create your SP for you. You might
consider modifying your ASP code to use a parameterized query to eliminate
the possibility of SQL Injection attacks.
"The Gekkster via SQLMonster.com" <forum@.SQLMonster.com> wrote in message
news:2be6e53d92854b93b2d238a8a16d82fb@.SQLMonster.com...
> Hi Hugo,
> Thanks for the input. I've tried to rework this a bit, and now have the
> following view and function (I've dropped some of the WHEREs for now to
> help sort this out):
> *******
> SELECT dbo.tblUnits.UnitInDatabase, dbo.tblRetailers.Active,
> dbo.tblUnits.CurrentlyInStock, dbo.SQUISH_V2.CLASS_TYPE,
> dbo.Units.AddedToInventory, dbo.tblRetailers.Name
> FROM dbo.SQUISH_V2 INNER JOIN
> dbo.tblUnits ON dbo.SQUISH_V2.UnitID => dbo.tblUnits.UnitID INNER JOIN
> dbo.tblRetailers ON dbo.tblRetailers.RetailerID => dbo.tblUnits.RetailerID
> *******
> *******
> ALTER FUNCTION dbo.udf_EDB_Current_Inventory (
> @.ClassTypeRequested varchar(255))
> RETURNS TABLE
> AS
> RETURN (SELECT COUNT(UnitInDatabase) AS CountOfUnitInDatabase
> FROM vw_EDB_Current_InventoryView
> WHERE CLASS_TYPE = @.ClassTypeRequested
> AND Active = 1
> AND CurrentlyInStock = 1)
> *******
> So I can now retrieve the needed count via the function, which is properly
> 'restrictive' based on the WHERE clause it contains. When I test this in
> SQL Server QA I get the correct result, like so:
> DECLARE @.B varchar(255)
> SET @.B = 'Custom'
> SELECT *
> FROM dbo.udf_EDB_Current_Inventory(@.B)
> So my question now is this: To minimize (or hopefully avoid) having to
> recode the ASP I'm using, is there a way to do this via a stored procedure
> (or even the above function) so that I can continue to make the call like
> this:
> *******
> objCommand1.CommandText = "usp_My_Procedure '" & objRS("SomeID") & "'"
> objCommand1.CommandType = adCmdStoredProc
> set objRS1 = objCommand1.Execute
> *******
> This part is still giving me some difficulty, as I don't seem to be
> getting
> the 'parameter' passed properly as was the case with using Access.
> Sorry for being so slow to get this - I can only plead ignorance from
> being
> new to UDFs and SPs. Thanks.
> --
> Message posted via http://www.sqlmonster.com|||Thanks, Michael - all works now as it should.
--
Message posted via http://www.sqlmonster.com

How to 'call' UDFs from SPs

New to SQL Server in general (2000 in particular) and working through the
relative difficulty of upsizing an Access '03 database that's currently
used in a small ASP web application. The database is generally hit via the
ADO command object, passing parameters as needed via CommandText.
Could someone show an example or two of how to 'call' a user-defined
function (with one parameter) from a stored procedure (also with one input
parameter, the same parameter that's used in the function), where the
procedure relies on a value returned by the function?
Please excuse if this is entirely too unclear, or is posted to the wrong
section. Thanks.
Message posted via http://www.droptable.comWithout knowing exactly what you're trying to do, you would call a UDF that
returns an integer as follows:
DECLARE @.i INTEGER
SET @.i = dbo.udfname(parameter)
Your stored procedure could make this call and use the variable @.i in
whatever fashion it needs. Not sure entirely what you're trying to do, or
how you're trying to do it, or the types you're dealing with, but that's the
basics of it.
Now if you're talking about the mechanics of the call from the ASP web app
side, we need to look at other stuff.
"The Gekkster via droptable.com" <forum@.droptable.com> wrote in message
news:17b4719d63284899b65bdc6083ed0ef8@.SQ
droptable.com...
> New to SQL Server in general (2000 in particular) and working through the
> relative difficulty of upsizing an Access '03 database that's currently
> used in a small ASP web application. The database is generally hit via the
> ADO command object, passing parameters as needed via CommandText.
> Could someone show an example or two of how to 'call' a user-defined
> function (with one parameter) from a stored procedure (also with one input
> parameter, the same parameter that's used in the function), where the
> procedure relies on a value returned by the function?
> Please excuse if this is entirely too unclear, or is posted to the wrong
> section. Thanks.
> --
> Message posted via http://www.droptable.com|||For stored procedures, it is not "necessary," although preferable, to
qualify the object with the owner. For UDFs, however, this is mandatory:
<owner/schema>.<UDF name><parameter list>
SET @.var = dbo.udfname(@.parm1, @.parm2, ..., @.parmn)
Sincerely,
Anthony Thomas
"Michael C#" <xyz@.abcdef.com> wrote in message
news:h2K0e.402$CN3.123@.fe11.lga...
Without knowing exactly what you're trying to do, you would call a UDF that
returns an integer as follows:
DECLARE @.i INTEGER
SET @.i = dbo.udfname(parameter)
Your stored procedure could make this call and use the variable @.i in
whatever fashion it needs. Not sure entirely what you're trying to do, or
how you're trying to do it, or the types you're dealing with, but that's the
basics of it.
Now if you're talking about the mechanics of the call from the ASP web app
side, we need to look at other stuff.
"The Gekkster via droptable.com" <forum@.droptable.com> wrote in message
news:17b4719d63284899b65bdc6083ed0ef8@.SQ
droptable.com...
> New to SQL Server in general (2000 in particular) and working through the
> relative difficulty of upsizing an Access '03 database that's currently
> used in a small ASP web application. The database is generally hit via the
> ADO command object, passing parameters as needed via CommandText.
> Could someone show an example or two of how to 'call' a user-defined
> function (with one parameter) from a stored procedure (also with one input
> parameter, the same parameter that's used in the function), where the
> procedure relies on a value returned by the function?
> Please excuse if this is entirely too unclear, or is posted to the wrong
> section. Thanks.
> --
> Message posted via http://www.droptable.com|||> "Michael C#" <xyz@.abcdef.com> wrote in message
> news:h2K0e.402$CN3.123@.fe11.lga...
...
> SET @.i = dbo.udfname(parameter)|||Thanks, guys.
I was trying to do something like this, although UDFs and SPs are new to me
and I'm obviously missing something here:
*******
CREATE PROCEDURE dbo.usp_My_Procedure
(
DECLARE @.CountOfWidgets INTEGER
SET @.CountOfWidgets = dbo.udf_My_Function(@.B)
)
AS
DECLARE @.B varchar(255)
SELECT COUNT(CountOfWidgets ) AS CountOfCountOfWidgets,
CountOfCountOfWidgets / CountOfWidgets AS Expr2
FROM dbo.udf_My_Function(@.B) CROSS JOIN
dbo.some_other_***
dbo.some_other_***
WHERE dbo.udf_My_Function(@.B)) AND some_other_criteria_***
GROUP BY CountOfWidgets, something_here_***
*******
In this scenario, @.B is a parameter that is passed (or needs to be passed)
from the ASP script to the procedure, like this:
*******
objCommand.CommandText = "usp_My_Procedure '" & objRS("WidgetBrand") & "'"
objCommand.CommandType = adCmdStoredProc
set objRS = objCommand.Execute
*******
The ASP part has been working fine when using Access; I'm just not yet up
to speed with procedures and functions for SQL Server.
Ideas...?
Message posted via http://www.droptable.com|||I think I see some potential "issues" in your SELECT statement already (I'm
assuming the ***'s are actually just where you blanked out the names for our
benefit of course). It would definitely help narrow down the problem if you
could post DDL, sample data and expected results. Your UDF code would help
troubleshoot it also.
You can try running your usp_My_Procedure in QA to see if it actually works
the way you expect it to also, or to see what error it returns if not.
Thanks
"The Gekkster via droptable.com" <forum@.droptable.com> wrote in message
news:316caf07f5ff49419d92cc87abdd0b7e@.SQ
droptable.com...
> Thanks, guys.
> I was trying to do something like this, although UDFs and SPs are new to
> me
> and I'm obviously missing something here:
> *******
> CREATE PROCEDURE dbo.usp_My_Procedure
> (
> DECLARE @.CountOfWidgets INTEGER
> SET @.CountOfWidgets = dbo.udf_My_Function(@.B)
> )
> AS
> DECLARE @.B varchar(255)
> SELECT COUNT(CountOfWidgets ) AS CountOfCountOfWidgets,
> CountOfCountOfWidgets / CountOfWidgets AS Expr2
> FROM dbo.udf_My_Function(@.B) CROSS JOIN
> dbo.some_other_***
> dbo.some_other_***
> WHERE dbo.udf_My_Function(@.B)) AND some_other_criteria_***
> GROUP BY CountOfWidgets, something_here_***
> *******
> In this scenario, @.B is a parameter that is passed (or needs to be passed)
> from the ASP script to the procedure, like this:
> *******
> objCommand.CommandText = "usp_My_Procedure '" & objRS("WidgetBrand") & "'"
> objCommand.CommandType = adCmdStoredProc
> set objRS = objCommand.Execute
> *******
> The ASP part has been working fine when using Access; I'm just not yet up
> to speed with procedures and functions for SQL Server.
> Ideas...?
> --
> Message posted via http://www.droptable.com|||Here is the (upsized) UDF:
*****
ALTER FUNCTION dbo.udf_EDB_Current_Inventory
(@.B varchar(255))
RETURNS TABLE
AS
RETURN ( SELECT COUNT(dbo.tblUnits.UnitInDatabase) AS
CountOfUnitInDatabase
FROM dbo.SQUISH_V2 CROSS JOIN
dbo.tblRetailers CROSS JOIN
dbo.tblUnits
WHERE (dbo.SQUISH_V2.CLASS_TYPE = @.B)
GROUP BY dbo.tblUnits.CurrentlyInStock, dbo.tblRetailers.Active
HAVING (dbo.tblUnits.CurrentlyInStock = 1) AND
(dbo.tblRetailers.Active = 1) )
*****
And this is the (upsized) SQL statement that needs to be incorporated into
the procedure, at least as 'determined/attempted' in the temporary Access
project (the cross joins are also courtesy of upsizing, and I'll need to
sort those out as well):
*****
SELECT COUNT(udf_EDB_Current_Inventory.CountOfUnitInDatabase) AS
CountOfCountOfUnitInDatabase,
CountOfCountOfUnitInDatabase /
udf_EDB_Current_Inventory.CountOfUnitInDatabase AS Expr2
FROM dbo.udf_EDB_Current_Inventory() udf_EDB_Current_Inventory
CROSS JOIN
dbo.SQUISH_V2 CROSS JOIN
dbo.tblRetailers CROSS JOIN
dbo.tblUnits
WHERE (dbo.SQUISH_V2.CLASS_TYPE = @.B) AND (DATEDIFF(d,
dbo.tblUnits.AddedToInventory, GETDATE()) > 30) AND (DATEDIFF(d,
dbo.tblUnits.AddedToInventory, GETDATE()) <= 60)
GROUP BY udf_EDB_Current_Inventory.CountOfUnitInDatabase,
dbo.tblUnits.CurrentlyInStock, dbo.tblRetailers.Active
HAVING (dbo.tblUnits.CurrentlyInStock = 1) AND
(dbo.tblRetailers.Active = 1)
*****
In trying to save/create the procedure I get the following error: "ADO
error: An insufficient number of arguments were supplied for the procedure
or function dbo.udf_EDB_Current_Inventory."
I'm not familiar enough with this, other than the error message is telling
me that either (i) the needed input parameter is not being passed; or (ii)
the function needs to include an output parameter to send back to the
procedure that's calling it?
Prior to this attempt to upsize, all data resided in SQL tables, and
queries were in Access (linked SQL tables). My hope was just to initially
move the queries into SQL Server and to take Access out of the picture. Too
bad I can't just use views with parameters, and worry about the greater
benefit of UDFs and SPs later. Or is that somehow possible...?
Message posted via http://www.droptable.com|||Sorry, Mike; I wasn't trying to correct what you said, but clarify a general
error most users have when they first start writing these. You had the
information there, but sometimes they need it spelled out.
Sincerely,
Anthony Thomas
"Michael C#" <xyz@.abcdef.com> wrote in message
news:UVL0e.8937$Qi6.1322@.fe09.lga...
> "Michael C#" <xyz@.abcdef.com> wrote in message
> news:h2K0e.402$CN3.123@.fe11.lga...
...
> SET @.i = dbo.udfname(parameter)|||On Fri, 25 Mar 2005 06:20:16 GMT, The Gekkster via droptable.com wrote:
(snip)
>In trying to save/create the procedure I get the following error: "ADO
>error: An insufficient number of arguments were supplied for the procedure
>or function dbo.udf_EDB_Current_Inventory."
Hi Gekkster,
From this part of the code you posted:

>ALTER FUNCTION dbo.udf_EDB_Current_Inventory
>(@.B varchar(255))
>RETURNS TABLE
I see that your user-defined function requires one argument.
In the stored procedure where you call the function, the call looks like
this:

>FROM dbo.udf_EDB_Current_Inventory() udf_EDB_Current_Inventory
And between the parentheses, there is no argument. The error message is
right: an insufficient number of arguments were supplied. Since I have
no idea what you are trying to accomplish, I can't give any suggestions
WHAT to put between the parentheses, but you better put SOMETHING there!
Oh, by the way:

>SELECT COUNT(udf_EDB_Current_Inventory.CountOfUnitInDatabase) AS
>CountOfCountOfUnitInDatabase,
> CountOfCountOfUnitInDatabase /
>udf_EDB_Current_Inventory.CountOfUnitInDatabase AS Expr2
is illegal in SQL Server. The whole SELECT statement is executed at
once; the alias CountOfCountOfUnitInDatabase can't be used in other
parts of the SELECT clause. The only place in a query where a column
alias can be used in in the ORDER BY clause.
The workaround is to either repeat the expression, or use a derived
table.
Best, Hugo
--
(Remove _NO_ and _SPAM_ to get my e-mail address)|||Hi Hugo,
Thanks for the input. I've tried to rework this a bit, and now have the
following view and function (I've dropped some of the WHEREs for now to
help sort this out):
*******
SELECT dbo.tblUnits.UnitInDatabase, dbo.tblRetailers.Active,
dbo.tblUnits.CurrentlyInStock, dbo.SQUISH_V2.CLASS_TYPE,
dbo.Units.AddedToInventory, dbo.tblRetailers.Name
FROM dbo.SQUISH_V2 INNER JOIN
dbo.tblUnits ON dbo.SQUISH_V2.UnitID =
dbo.tblUnits.UnitID INNER JOIN
dbo.tblRetailers ON dbo.tblRetailers.RetailerID =
dbo.tblUnits.RetailerID
*******
*******
ALTER FUNCTION dbo.udf_EDB_Current_Inventory (
@.ClassTypeRequested varchar(255))
RETURNS TABLE
AS
RETURN (SELECT COUNT(UnitInDatabase) AS CountOfUnitInDatabase
FROM vw_EDB_Current_InventoryView
WHERE CLASS_TYPE = @.ClassTypeRequested
AND Active = 1
AND CurrentlyInStock = 1)
*******
So I can now retrieve the needed count via the function, which is properly
'restrictive' based on the WHERE clause it contains. When I test this in
SQL Server QA I get the correct result, like so:
DECLARE @.B varchar(255)
SET @.B = 'Custom'
SELECT *
FROM dbo.udf_EDB_Current_Inventory(@.B)
So my question now is this: To minimize (or hopefully avoid) having to
recode the ASP I'm using, is there a way to do this via a stored procedure
(or even the above function) so that I can continue to make the call like
this:
*******
objCommand1.CommandText = "usp_My_Procedure '" & objRS("SomeID") & "'"
objCommand1.CommandType = adCmdStoredProc
set objRS1 = objCommand1.Execute
*******
This part is still giving me some difficulty, as I don't seem to be getting
the 'parameter' passed properly as was the case with using Access.
Sorry for being so slow to get this - I can only plead ignorance from being
new to UDFs and SPs. Thanks.
Message posted via http://www.droptable.com

How To call TRIGGER in VB.net 2005

i hav written a trigger in SQLEXPRESS DB but i dnt knw how to call in vb.net 2005...

Move the source code from trigger to stored proc, create the stored proc with moved code & call the SP from your ADO.NET.

|||

You do not call triggers. They fire when the event, it is related to, occurs. Check BOL for more information about triggers.

AMB

How to call the processing of a cube ?

I need to automatically process a cube. Do I have to use an Analysis Managment Object (AMO) ?

Otherwise, I know that it is possible to create a Sql Agent Job to run periodically, but I don't want to schedule this task. In fact, I need to "call" the processing of my cube, wich will run between other jobs. The "caller" is a Visual Basic 6 program from wich I am able to launch .exe files.

thanks

Hello. I am not sure if you are taking about SSSAS2000 or SSAS2005?

Anyway, you can make a dts-package in SQL Server 2000 or a SSIS-package in BI-Dev Studio that process the dimensions and the cubes.

These packages are possible to call by a VB-application but I think you must use VB6 for dts and VB.Net 2005 for SSIS(Integration services).

HTH

Thomas Ivarsson

|||

Hi. You can also use the command prompt utility "DTEXEC" from VB6 to call a package developed with SSIS if you have to. However, Thomas' suggestion of using VB .NET 2005 is best. Here's more information on the DTEXEC utility.

http://msdn2.microsoft.com/en-us/library/ms143706.aspx

Paul Goldy

|||

Here are a couple of articles I published with step-by-step setup for the DTS / SSIS scenarios involved:

For SSAS 2k (DTS):

http://www.databasejournal.com/features/mssql/article.php/3503201

For SSAS 2k5 (SSIS):

http://www.databasejournal.com/features/mssql/article.php/3584306

Good Luck!

Bill

William E. Pearson III
CPA, CMA, CIA, MCSE, MCDBA
Island Technologies Inc.
931 Monroe Drive
Suite 102-321
Atlanta, GA 30308

404.872.5972 Office
wep3@.islandtechnologies.com
wep3@.msas-architect.com

www.msas-architect.com
-- -- --

Publisher Sites:

http://www.databasejournal.com/article.php/1459531

http://www.sql-server-performance.com/bill_pearson.asp

http://www.informit.com/authors/bio.asp?a=862acd62-4662-49ae-879d-541c8b4d656f

http://www.2000trainers.com/section.aspx?sectionID=17

|||

Thanks ! What I need is in the first article link you posted, Bill. I will create a DTS package.

The problem is, I can't do the step #9 on page 3. I don't have the Analysis Services Processing Task ICON in the TASKS TOOLBAR ... ?

If that can helps, I work with : SQL Server Enterprise Manager version 8.0
Analysis Manager version 5
Visual Basic 6 (the program that calls the DTS package)

So, what do you think ?

PS - I found how to call the package with VB6 on this page :
http://www.sqlservercentral.com/columnists/bknight/executingpackagefromvisualbasic.asp

EDIT : I found on the Microsoft web site that the Analysis Processing task is available only when SQL Server 2000 Analysis Services is installed.
http://www.microsoft.com/technet/prodtechnol/sql/2000/deploy/dtssql2k.mspx

How to call talbe/SP from Linked server with out database and user

Dear Friends,
Usually we call tabal and SP like given below.
select * from [linkedserver].[database].[dbo].[TableName]
EXEC [linkedserver].[database].[dbo].usp_storedprocedure
but I like to all with out database and username.
I tryed like below
select * from [linkedserver]...[TableName]
OR
select * from [linkedserver]..[user].[TableName]
It's gives error
Server: Msg 7313, Level 16, State 1, Line 1
Invalid schema or catalog specified for provider 'MSDASQL'.
OLE DB error trace [Non-interface error: Invalid schema or catalog
specified for the provider.].
Please help me to achive this.
Thasks and regards,
Rajesh
On Wed, 14 Sep 2005 07:57:08 -0700, Rajesha wrote:

>Dear Friends,
>Usually we call tabal and SP like given below.
> select * from [linkedserver].[database].[dbo].[TableName]
> EXEC [linkedserver].[database].[dbo].usp_storedprocedure
>but I like to all with out database and username.
>I tryed like below
>select * from [linkedserver]...[TableName]
>OR
>select * from [linkedserver]..[user].[TableName]
>It's gives error
>Server: Msg 7313, Level 16, State 1, Line 1
>Invalid schema or catalog specified for provider 'MSDASQL'.
>OLE DB error trace [Non-interface error: Invalid schema or catalog
>specified for the provider.].
>Please help me to achive this.
>Thasks and regards,
>Rajesh
Hi Rajesh,
You can't leave out the databasename. A linked server might hold more
than one database, so you have to specify that part.
I believe that you can leave out the owner, but I'm not sure, and I
can't test that right now. However, it is recommended that you always
include the owner. This helps SQL Server find the object more quickly,
and it helps reduce the number of recompiles.
Best, Hugo
(Remove _NO_ and _SPAM_ to get my e-mail address)

How to call subreports from a main report

HI there,
I want to know if someone know how to call subreports that depends from one
main report.
Could you help me?
Regards,
Oscar.On Nov 9, 10:48 am, Remigio Oscar Iglesias - Argentina
<RemigioOscarIglesiasArgent...@.discussions.microsoft.com> wrote:
> I want to know if someone know how to call subreports that depends from one
> main report.
Create a Main Report (named "Report A").
Create a second report (the Subreport named "Report B") that receives
a Parameter. Use the Parameter in the Data query.
Add a Subreport object to the Main Report, and open the object's
Property window. Set the object's "Subreport" Property to the name of
the Sub Report (Report B). Go to the Parameters Tab. Set Report B's
Parameter to a value calculated in Report A. Now query that is made
in Report B depends on data provided in Report A.
-- Scott|||Note that your subreport is just a regular report you are embedding into
your main report. The subreport should be designed with parameters. Test the
subreport fully and then Drag and drop your subreport onto the main report.
Right mouse click on subreport, parameters. Map the parameter of the
subreport to whatever you want from the main report (it can be a field if
you are doing something like a master-detail report, you can base it on the
parameters for the main report).
Bruce Loehle-Conger
MVP SQL Server Reporting Services
"Remigio Oscar Iglesias - Argentina"
<RemigioOscarIglesiasArgentina@.discussions.microsoft.com> wrote in message
news:BDD3CE41-8B8B-48BD-92A1-0C0BA75FE5EB@.microsoft.com...
> HI there,
> I want to know if someone know how to call subreports that depends from
> one
> main report.
> Could you help me?
> Regards,
> Oscar.
>

How to call Stored Procedures?

How to call store procedures in VB 6.0 application?You will probably have to use ADO or a similar databaseaccess technique. Look it up in the online help, it should explain most of what you need to do much clearly than I can.

:o

How to call stored procedure to table?

Hi....

I have problem and I need your help

I stored a procedure in the Projects Folder in my computer

and I want to return the procedure result in a column inside table

How I can do that???

thank you

Please any one can help me??????????

|||

Hi,

From your description, you have mentioned that you want to return the procedure result in a column.

Well, do you mean you want to select a column from your database with several rows, and then get these rows from your stored procedure, right?

If so, you can execute a procedure that return rows. To execute a stored procedure that returns row, you can run a TableAdapter query that is configured to run a stored procedure (for example, CustomersTableAdapter.Fill(CustomersDataTable)).

If your application does not use TableAdapters, call the ExecuteReader method on a command object, setting its CommandType property to StoredProcedure. ("Command object" refers to the specific command for the .NET Framework Data Provider that your application is using. For example, if your application is using the .NET Framework Data Provider for SQL Server, the command object would be SqlCommand.)

For more information, see
http://msdn2.microsoft.com/en-us/library/d7125bke(VS.80).aspx

Thanks.

how to call stored procedure from another stored procedure?

is it possible to call a stored procedure from another stored procedure?Inside your first Stored Procedure:

exec <name of SP to run> <Eventual Parameters this SP requires>

Here is a link to all you want to know about executing SPs from other SPs. You can even Execute SPs on other SQL Servers.

how to call sql store procedure in asp.net

I create a store procedure in sql, how do I call it?

thankssUse SqlCommand like this:

YourCommandName = New SQLCommand("YourStoredProcedureHere",YourConnection)
YourCommandName.CommandType = CommandType.StoredProcedure
You can also add parameters to the SqlCommand.|||got it.

thankss

How to call SQL server Reports in VB 6.0

Hi
Present we are using crystal reports 8.5 in VB application .
database is SQL server 2000.
How can convert existing Crystall reports into SQl Server reports and How to
call SQL server Reports in VB 6.0 as like Crystal reports.
Would appreciate if any one gives suggestion on this.
Thanks
VenuThere are two ways. One, implement SOAP in VB and use web services (not
trivial). The other is to embed an IE control in your app and use URL
integration.
Bruce Loehle-Conger
MVP SQL Server Reporting Services
"venu gopal" <venu gopal@.discussions.microsoft.com> wrote in message
news:910A2BBE-A706-4B5F-90B3-088B7CDDB7F8@.microsoft.com...
> Hi
> Present we are using crystal reports 8.5 in VB application .
> database is SQL server 2000.
> How can convert existing Crystall reports into SQl Server reports and How
> to
> call SQL server Reports in VB 6.0 as like Crystal reports.
> Would appreciate if any one gives suggestion on this.
> Thanks
> Venu
>

How to call SP of one SQL server from other SQL server

Hi,

In my application environment, we have data will be in available in different SQL servers.

I hava requirement to call the SP of on SQL server from the SP in the other SQL server.

Can any one help me out for a solution which will be faster?

Please note that I cant go for the linked servers as the other SQL severs credentials will be stored in a Database table and it has to be used in run time of the SPs.

Awaiting quick response from you all..

Thanks in advance.

-Thams

YOu can use the openrowset for that:

DECLARE @.USERNAME VARCHAR(50)

DECLARE @.Password VARCHAR(50)

DECLARE @.SQLString VARCHAR(500)

SET @.USERNAME = 'SomeUser'

SET @.Password = 'SomePassword'

SET @.SQLString = '

SELECT a.*

FROM OPENROWSET(''SQLNCLI'', ''Data Source=.;UserName=' + @.USERNAME + ';Pwd=' + @.Password + ';'',

''EXEC Northwind.dbo.[Ten Most Expensive Products]'') AS a;

'

SELECT @.SQLString

EXEC(@.SQLString)

Jens K. Suessmeyer

http://www.sqlserver2005.de

Friday, March 9, 2012

How to call ReportViewer Refresh method?

I have a web form with a textbox that contains a parameter for a report defined in the ReportViewer control. I want to refresh the report when the user clicks on my refresh button. I can't find the Refresh method. It works if I click on the reviewer's refresh button, but my users need to see that big button that says Refresh. Any ideas of how to call the refresh method? ThanksFound it.

Me.ReportViewer1.LocalReport.Refresh()

How to call Reporting Service

I am not sure how to do it. Please help.
I am trying to call a report I did in REporting Service 2005. I have a web
form where user will go and make selection parameter liek Employee name,
start and End Date.
How I can pass this parameter from my web Form to Reporting Service
Thanks
TanweerSimplist thing to do is to start with URL integration. If you have VS 2005
there is a reportviewer webform control (and a winform control) that is very
good and I highly recommend using it. I am using the Winform version of the
control. Search on URL in Books OnLine.
Bruce Loehle-Conger
MVP SQL Server Reporting Services
"Tanweer" <Tanweer@.discussions.microsoft.com> wrote in message
news:E58A9D53-7BF6-4E13-B60D-113EB0D2DFEA@.microsoft.com...
>I am not sure how to do it. Please help.
> I am trying to call a report I did in REporting Service 2005. I have a web
> form where user will go and make selection parameter liek Employee name,
> start and End Date.
> How I can pass this parameter from my web Form to Reporting Service
> Thanks
> Tanweer

How to call report via url in RSReportHost.exe

I am calling my reports via URL, but it presents the report in IE with the url so the users might change the parameters value in IE addressbar. but i see RSReportHost.exe does'nt show the url at all.

Is it possible to show or call a report via URL using RSReportHost.exe

I am using VS 2003 with SQL RS 2005, i don't have a reportviewer control available to use.

Please help guys.

Thank you fery much.

RSReportHost is a desktop application designed for debugging reports. So, the short answer to your question is no. Moreover, URL access is not a very secure way to request reports. The Report ViewerASP.NET control does a reasonable job to hide the parameter values during reposts but it is not foolproof as well. Regardless of the fact that you don’t use the ASP.NET Report, RS 2005 URL addressability uses it behind the scenes by redirecting the user to the ReportViewer.aspx page. So, one way to mitigate the security risk with parameters is to request the report without parameters and rely on the Report Viewer to handle them. Stricter security requirements may require the web application to handle the parameters on the server side.

|||

Thank you very much Teo.

But VS 2003 does'nt have a reportviewer to use with RS 2005.

Microsoft only released the viewer with vs 2005.

I have a very big project fully developed using vs 2003 and lot of state and federal construction projects are using the tool. and also we have integrated third party controls which specifically uses framework 1.1. i don't have an open option to switch to vs 2005 soon might have to wait until all the migration related issues gets cleared.

my current options are to use render webservices to load reports via pdf streams. which i am using. are there any other methods available using vs 2003 and sql rs 2005 please help.

Thank you once again. i read about you on google a lot.

|||

Just to clarify, I was referring to the server ReportViewer.aspx page which the user is automatically redirected to with URL addressability. So, if the user clicks on a URL link which points to a report (e.g. http://localhost/reportserver?%2fAdventureWorks+Sample+Reports%2fCompany+Sales&rs:Command=Render) , the server will redirect her to that page which uses the ReportViewer ASP.NET Report Viewer control behind the scenes. Therefore, you don’t have to upgrade to VS.NET 2005 at all.

|||

Thks Teo, But the problem with URL is the users can manipulate the url parameters by themselves in the IE address bar. I don't want the users manipulate the url's.

|||

True. You have different options to address this depending on the security risk.

1. If you think that hacking the report URL goes beyond the skills of your users, you may be fine with the ReportViewer parameter hiding.

2. You can use the user identity (User!UserID) to filter the parameter available values and/or report data (row-level security).

3. You can configure the Report Server to be accessable from your application server only and not directly from the end users.

4. You can use a trusted account between your application server and Report Server. All report requests will go under this account and you will secure the report catalog accordingly. These security policies will prevent the end users from requesting reports directly.

How to call remote object using C# Stored procedure

I want to call a windows based service running with remote objects listner from a C# Stored procedure. Any idea how to do that?

Hi-

I'm actually not quite sure what you would like to do, but if you could clarify, I can try to help.

I think your question may be how to do this within C#. 99.9% of the time, if it’s possible to do in C#, then it’s possible to do in SQLCLR (under atleast the UNSAFE permission set).

I'd recommend using MSDN or clarifying what you need to do to make your scenario work within a console application. Once you have your scenario working in a console application, you could port your code to map a stored procedure to an entry point.

Thanks!
Jason

|||

I am running a windows service with one exposed object using remoting.

I want to call that from stored procedure/function created in SQL Server using C#.