Showing posts with label procedure. Show all posts
Showing posts with label procedure. Show all posts

Friday, March 30, 2012

How to value parameters for sqldatasource

I set up a sqldatasource based on a stored procedure which takes one parameter. The sqldatasrouce wizard generates the following code for the parameter below. The question is how do I value the DeptID parameter on the load of the form. I tried the following code in the load of the page, but get a null reference error:

Me.SqlDataSource1.InsertParameters("DeptID").DefaultValue = Session("DeptID")

<asp:SqlDataSource ID="SqlDataSource1" runat="server"
ConnectionString="<%$ ConnectionStrings:FDConn %>"
SelectCommand="GetTruckStatus" SelectCommandType="StoredProcedure">
<SelectParameters>
<asp:Parameter Name="DeptID" Type="Int32" />
</SelectParameters>
</asp:SqlDataSource>
<radG:RadGrid ID="RadGrid1" runat="server">
</radG:RadGrid>

You've set the value of an InsertParameter, but you are performing a Select, not an Insert. Anyway, the SqlDataSource offers a number of different parameter types. One of them is an <asp:SessionParameter>. Use that instead of the generic<asp:Parameter> that you are currently using. You can reconfigure the SqlDataSource to generate it automatically. Click the WHERE button when applying the Select Statement, and in the Source dropdown, choose Session.

|||

Mike,
Thanks for the information. I went back into the configure the sqldatasrouce, but if you chose to use a stored procedure, the button for selecting "Where" is grayed out. I assumed that since the code was generated from vb and from the stored procedure I selected, vb would know the type of parameter it had to generate.


Regards,
Tom

|||

Mike,

I went back into the code and used the "SelectParameter" type and all worked well. Thanks for pointing me in the right direction.

Tom

Wednesday, March 28, 2012

How to Using Variable in OPENROWSET T-SQL

Hi,
How to use variable as parameter in stored procedure using OPENROWSET
'
I try the query below, but get an error. Please help me.
DECLARE @.job varchar(5)
SET @.job='RefreshTLMReport'
SELECT *
FROM
OPENROWSET('sqloledb'
, 'server=reportsvr;trusted_connection=yes
'
, 'set fmtonly off exec msdb..sp_help_job @.job_name='
+ @.job + ')'
ThanksResant
declare @.par int,@.sql varchar(8000)
set @.par=1
set @.sql ='exec mysp ' + cast(@.par as varchar(10))+''''
EXEC ('select *
from
OPENROWSET(''SQLOLEDB'',''SERVER=name;DA
TABASE=pubs;UID=sa;PWD=pass;'',''set
fmtonly off; ' + @.sql+')')
"Resant" <resant_v@.yahoo.com> wrote in message
news:1131512827.293294.303190@.g44g2000cwa.googlegroups.com...
> Hi,
> How to use variable as parameter in stored procedure using OPENROWSET
> '
> I try the query below, but get an error. Please help me.
> DECLARE @.job varchar(5)
> SET @.job='RefreshTLMReport'
> SELECT *
> FROM
> OPENROWSET('sqloledb'
> , 'server=reportsvr;trusted_connection=yes
'
> , 'set fmtonly off exec msdb..sp_help_job @.job_name='
> + @.job + ')'
>
> Thanks
>|||Hi
sp_help_job will not return a single resultset therefore you can't use it in
OPENQUERY. Your code is also truncating the jobname to 5 characters. Try
DECLARE @.job sysname
SET @.job='RefreshTLMReport'
EXEC reportsvr.msdb..sp_help_job @.job_name=@.job
John
"Resant" wrote:

> Hi,
> How to use variable as parameter in stored procedure using OPENROWSET
> '
> I try the query below, but get an error. Please help me.
> DECLARE @.job varchar(5)
> SET @.job='RefreshTLMReport'
> SELECT *
> FROM
> OPENROWSET('sqloledb'
> , 'server=reportsvr;trusted_connection=yes
'
> , 'set fmtonly off exec msdb..sp_help_job @.job_name='
> + @.job + ')'
>
> Thanks
>|||I think it's much better, but thanks all.
DECLARE @.job varchar(5)
SET @.job='RefreshTLMReport'
SELECT *
FROM
OPENROWSET('sqloledb'
, 'server=reportsvr;trusted_connection=yes
'
, 'set fmtonly off exec msdb..sp_help_job')
WHERE name=@.job|||Hi Resant
This will produce different results to running it directly and specifying
the @.job_name!
You have still declared @.job as varchar(5) instead of a sysname.
John
"Resant" wrote:

> I think it's much better, but thanks all.
> DECLARE @.job varchar(5)
> SET @.job='RefreshTLMReport'
> SELECT *
> FROM
> OPENROWSET('sqloledb'
> , 'server=reportsvr;trusted_connection=yes
'
> , 'set fmtonly off exec msdb..sp_help_job')
> WHERE name=@.job
>sql

How to use xslt with tsql ?

If Im within a tsql stored procedure, is there a way to use xslt on an xml type ?

Lets say I have an xml string that im reading in as a stored procedure parameter. This string has an attribute on the parent element. Based on this parent element, id like to load the specific xslt transform which could be in another table. What im wondering however, is how to use xslt without calling out to a clr procedure.

help?

You couldn't use XSLT in current version of SQL Server. xml data type support only XQuery/XPath statements now.

But you could XQuery statements as a replacement of XSLT (of couse, for simple cases)

|||

Well, actually I should have posted this in the SSIS forum, because thats where im trying to do this. And it appears that i should be using the xml task

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

sql

How to use xslt with tsql ?

If Im within a tsql stored procedure, is there a way to use xslt on an xml type ?

Lets say I have an xml string that im reading in as a stored procedure parameter. This string has an attribute on the parent element. Based on this parent element, id like to load the specific xslt transform which could be in another table. What im wondering however, is how to use xslt without calling out to a clr procedure.

help?

You couldn't use XSLT in current version of SQL Server. xml data type support only XQuery/XPath statements now.

But you could XQuery statements as a replacement of XSLT (of couse, for simple cases)

|||

Well, actually I should have posted this in the SSIS forum, because thats where im trying to do this. And it appears that i should be using the xml task

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

How to use xp_trace_generate_event

Hi
I have created a stored procedure that create a trace on SQL 7 and start
the trace. but this procedure is sending the trace to a file. I want to send
the output of trace to a table.
I am using xp_trace_setqueuedestination and specified the proper destination
table, but still I am not able to get the data in the table.
After some research I find out that I have to xp_trace_generate_event.
But I don't know how to use xp_trace_generate_event to generate the output
to a trace table.
Can someone help in doing this?
Or is there some undocumented stored procedure like sp_trace_getdata that
exist in SQL 2000.
Thanks in advance.
Pushkar
It's hard to say without seeing what you are specifying for
xp_trace_setqueuedestination but try to qualify the table
for the table parameter, e.g. 'YourDB..YourTable'
Make sure you are using 4 for the destination parameter.
-Sue
On Wed, 8 Jun 2005 16:01:48 +0530, "Pushkar"
<tiwaripushkar@.yahoo.co.in> wrote:

>Hi
>I have created a stored procedure that create a trace on SQL 7 and start
>the trace. but this procedure is sending the trace to a file. I want to send
>the output of trace to a table.
>I am using xp_trace_setqueuedestination and specified the proper destination
>table, but still I am not able to get the data in the table.
>After some research I find out that I have to xp_trace_generate_event.
>But I don't know how to use xp_trace_generate_event to generate the output
>to a trace table.
>Can someone help in doing this?
>Or is there some undocumented stored procedure like sp_trace_getdata that
>exist in SQL 2000.
>Thanks in advance.
>Pushkar
>
|||Hi
Below is the script I am using:
-- Create a Queue
declare @.rc int
declare @.QueueHandle int
exec @.rc = xp_trace_addnewqueue 1000, 5000, 95, 90, 67354401, @.QueueHandle
output
if (@.rc != 0) goto error
-- Set the events
-- SQL Server 2000 specific events will not be scripted
exec xp_trace_seteventclassrequired @.QueueHandle, 10, 1
exec xp_trace_seteventclassrequired @.QueueHandle, 12, 1
exec xp_trace_seteventclassrequired @.QueueHandle, 14, 1
exec xp_trace_seteventclassrequired @.QueueHandle, 15, 1
exec xp_trace_seteventclassrequired @.QueueHandle, 17, 1
-- Set the Filters
exec xp_trace_setappfilter @.QueueHandle, N'', N'SQL Profiler'
-- set the destinations
exec xp_trace_setqueuedestination @.QueueHandle, 4, 1,
N'sql-nt4',N'[master]..[Untitled - 1]'
-- save the definition in the registry
exec xp_trace_savequeuedefinition @.QueueHandle, N'Untitled - 1', 1
-- display queue handle for future references
select QueueHandle=@.QueueHandle
goto finish
error:
select ErrorCode=@.rc
finish:
go
Please suggest what changes in script should I do to get the trace result in
the table.
Thanks
Pushkar
"Sue Hoegemeier" <Sue_H@.nomail.please> wrote in message
news:t0pda1dnmf5raf844u5laj2ct4iaooktvm@.4ax.com... [vbcol=seagreen]
> It's hard to say without seeing what you are specifying for
> xp_trace_setqueuedestination but try to qualify the table
> for the table parameter, e.g. 'YourDB..YourTable'
> Make sure you are using 4 for the destination parameter.
> -Sue
> On Wed, 8 Jun 2005 16:01:48 +0530, "Pushkar"
> <tiwaripushkar@.yahoo.co.in> wrote:
send[vbcol=seagreen]
destination[vbcol=seagreen]
output
>

Monday, March 26, 2012

How to use user defined function in stored procedure?

Hello friends,
I want to use my user defined function in a stored procedure.
I have used it like ,
select statement where id = dbo.getid(1,1,'abc')
//dbo.getid is a user defined function.
procedure is created successfully but when i run it by exec procedurename parameter
I get error that says
"Cannot find either column "dbo" or the user-defined function or aggregate "dbo.getid", or the name is ambiguous."

Can any body help me?
Rgds,
Kiran.

Hi,

guess you created the function not with the owner / schema (depending on which version you are working with) "dbo". So try to find the schema / owner with

SELECT * FROM INFORMATION_SCHEMA.Routines
Where Routine_Name = ''getid"

One column is SPECIFIC_SCHEMA, lookfor this and try to rewrite the statement in your proc. The fact that the non-existence of the function isn′t throwing an error is called "deferred name resolution".

http://msdn.microsoft.com/library/en-us/createdb/cm_8_des_07_5wa6.asp

HTH, Jens Suessmeyer.

http://www.sqlserver2005.de

|||Thanks for the solution
Rgds,
Kiran Suthar

how to use use <db name> in store procedure

Hi
I am passing database name as a parameter in the stored procedure
I want to create stored procedure in master and want to access the database
systables depending on the input to the stored procedure.
How do I go in that specific database as I can not use "use @.dbname"
in store procedure.
Thanks
MangeshMangesh Deshpande wrote:
> Hi
> I am passing database name as a parameter in the stored procedure
> I want to create stored procedure in master and want to access the
> database systables depending on the input to the stored procedure.
> How do I go in that specific database as I can not use "use @.dbname"
> in store procedure.
> Thanks
> Mangesh
The easiest way is probably to use dynamic SQL. Just be really careful
of SQL Injection issues. Make sure the procedure does adequate data
validation.
Creating procedures in master is not recommended. For one reason, they
may disappear with service pack installations. I think you're better off
creating a shared database to store all your "shared" procedures.
Microsoft does this in SQL Server with the msdb database. It just
requires using the database name when executing the procedure.
-- Dynamic SQL
Declare @.n nvarchar(1000)
Declare @.db nvarchar(128)
Set @.db = N'[pubs]'
Set @.n = N'Select * from ' + @.db + N'.[dbo].[sysobjects]'
Exec sp_executesql @.n
David Gugick
Imceda Software
www.imceda.com|||Thanks David.
Is there a best practices document you know of for coding in sqlserver?
"David Gugick" wrote:
> Mangesh Deshpande wrote:
> > Hi
> >
> > I am passing database name as a parameter in the stored procedure
> > I want to create stored procedure in master and want to access the
> > database systables depending on the input to the stored procedure.
> >
> > How do I go in that specific database as I can not use "use @.dbname"
> > in store procedure.
> >
> > Thanks
> > Mangesh
> The easiest way is probably to use dynamic SQL. Just be really careful
> of SQL Injection issues. Make sure the procedure does adequate data
> validation.
> Creating procedures in master is not recommended. For one reason, they
> may disappear with service pack installations. I think you're better off
> creating a shared database to store all your "shared" procedures.
> Microsoft does this in SQL Server with the msdb database. It just
> requires using the database name when executing the procedure.
>
> -- Dynamic SQL
> Declare @.n nvarchar(1000)
> Declare @.db nvarchar(128)
> Set @.db = N'[pubs]'
> Set @.n = N'Select * from ' + @.db + N'.[dbo].[sysobjects]'
> Exec sp_executesql @.n
>
> --
> David Gugick
> Imceda Software
> www.imceda.com
>sql

how to use use <db name> in store procedure

Hi
I am passing database name as a parameter in the stored procedure
I want to create stored procedure in master and want to access the database
systables depending on the input to the stored procedure.
How do I go in that specific database as I can not use "use @.dbname"
in store procedure.
Thanks
Mangesh
Mangesh Deshpande wrote:
> Hi
> I am passing database name as a parameter in the stored procedure
> I want to create stored procedure in master and want to access the
> database systables depending on the input to the stored procedure.
> How do I go in that specific database as I can not use "use @.dbname"
> in store procedure.
> Thanks
> Mangesh
The easiest way is probably to use dynamic SQL. Just be really careful
of SQL Injection issues. Make sure the procedure does adequate data
validation.
Creating procedures in master is not recommended. For one reason, they
may disappear with service pack installations. I think you're better off
creating a shared database to store all your "shared" procedures.
Microsoft does this in SQL Server with the msdb database. It just
requires using the database name when executing the procedure.
-- Dynamic SQL
Declare @.n nvarchar(1000)
Declare @.db nvarchar(128)
Set @.db = N'[pubs]'
Set @.n = N'Select * from ' + @.db + N'.[dbo].[sysobjects]'
Exec sp_executesql @.n
David Gugick
Imceda Software
www.imceda.com
|||Thanks David.
Is there a best practices document you know of for coding in sqlserver?
"David Gugick" wrote:

> Mangesh Deshpande wrote:
> The easiest way is probably to use dynamic SQL. Just be really careful
> of SQL Injection issues. Make sure the procedure does adequate data
> validation.
> Creating procedures in master is not recommended. For one reason, they
> may disappear with service pack installations. I think you're better off
> creating a shared database to store all your "shared" procedures.
> Microsoft does this in SQL Server with the msdb database. It just
> requires using the database name when executing the procedure.
>
> -- Dynamic SQL
> Declare @.n nvarchar(1000)
> Declare @.db nvarchar(128)
> Set @.db = N'[pubs]'
> Set @.n = N'Select * from ' + @.db + N'.[dbo].[sysobjects]'
> Exec sp_executesql @.n
>
> --
> David Gugick
> Imceda Software
> www.imceda.com
>

how to use use <db name> in store procedure

Hi
I am passing database name as a parameter in the stored procedure
I want to create stored procedure in master and want to access the database
systables depending on the input to the stored procedure.
How do I go in that specific database as I can not use "use @.dbname"
in store procedure.
Thanks
MangeshMangesh Deshpande wrote:
> Hi
> I am passing database name as a parameter in the stored procedure
> I want to create stored procedure in master and want to access the
> database systables depending on the input to the stored procedure.
> How do I go in that specific database as I can not use "use @.dbname"
> in store procedure.
> Thanks
> Mangesh
The easiest way is probably to use dynamic SQL. Just be really careful
of SQL Injection issues. Make sure the procedure does adequate data
validation.
Creating procedures in master is not recommended. For one reason, they
may disappear with service pack installations. I think you're better off
creating a shared database to store all your "shared" procedures.
Microsoft does this in SQL Server with the msdb database. It just
requires using the database name when executing the procedure.
-- Dynamic SQL
Declare @.n nvarchar(1000)
Declare @.db nvarchar(128)
Set @.db = N'[pubs]'
Set @.n = N'Select * from ' + @.db + N'.[dbo].[sysobjects]'
Exec sp_executesql @.n
David Gugick
Imceda Software
www.imceda.com|||Thanks David.
Is there a best practices document you know of for coding in sqlserver?
"David Gugick" wrote:

> Mangesh Deshpande wrote:
> The easiest way is probably to use dynamic SQL. Just be really careful
> of SQL Injection issues. Make sure the procedure does adequate data
> validation.
> Creating procedures in master is not recommended. For one reason, they
> may disappear with service pack installations. I think you're better off
> creating a shared database to store all your "shared" procedures.
> Microsoft does this in SQL Server with the msdb database. It just
> requires using the database name when executing the procedure.
>
> -- Dynamic SQL
> Declare @.n nvarchar(1000)
> Declare @.db nvarchar(128)
> Set @.db = N'[pubs]'
> Set @.n = N'Select * from ' + @.db + N'.[dbo].[sysobjects]'
> Exec sp_executesql @.n
>
> --
> David Gugick
> Imceda Software
> www.imceda.com
>

How to use t-sql to email and attachment

I am new to sql and want to write a stored procedure to email a database group an attachment of a report that was created. Can someone please point me in the write direction thanks.WHat do you mean by report ? Is it a report like from Reporting Services or is it just a results set from a query ? DO you want to swnd it via SQL Mail or SMTP ? DO you use SQL 2k or SQL 2k5 ?

HTH, Jens Suessmeyer.

http://www.sqlserver2005.de|||I want to send an export via smtp using sql 2005. Is there a built-in stored procedure that will allow me to send an smtp message, and attach my export csv.|||You could use the new Database Mail feature. But for your needs it is easier to use a SSIS package since you can export the data from table(s) to file and email it using built-in tasks. You could do the same within SQL Server also but you have to xp_cmdshell to run BCP out and that poses security risks among other things.

How to use the same stored procedure to display two different char

I need to display two charts on a report based on the same stored procedure
that accepts a single parameter. I do not wish to be promted for the
parameter. Instead, I would like to pass two different values to each chart
within the report.
Please advise.
Thanks,
KonstantinHow do you know what value to pass it?
Anyway, something to get you going in the right direction. First thing to
realize is that query parameters and report parameters are two different
things. RS automatically creates a report parameter for you for each stored
procedure query parameter it sees. But, you don't have to use it. You can
map it to an expression instead. Click on the ..., parameters tab. On the
right pick change it from mapping to a report parameter and map it to an
expression instead.
Bruce Loehle-Conger
MVP SQL Server Reporting Services
"Konstantin Shaumyan" <KonstantinShaumyan@.discussions.microsoft.com> wrote
in message news:3A7E2C6B-FF43-4993-9B21-04EA79316410@.microsoft.com...
>I need to display two charts on a report based on the same stored procedure
> that accepts a single parameter. I do not wish to be promted for the
> parameter. Instead, I would like to pass two different values to each
> chart
> within the report.
> Please advise.
> Thanks,
> Konstantin|||Thanks for the tip.
I created two datasets based on the same stored procedure for each graph and
set my parameter for each dataset to literals.
Everything worked as expected.
Regards,
Konstantin
"Bruce L-C [MVP]" wrote:
> How do you know what value to pass it?
> Anyway, something to get you going in the right direction. First thing to
> realize is that query parameters and report parameters are two different
> things. RS automatically creates a report parameter for you for each stored
> procedure query parameter it sees. But, you don't have to use it. You can
> map it to an expression instead. Click on the ..., parameters tab. On the
> right pick change it from mapping to a report parameter and map it to an
> expression instead.
>
> --
> Bruce Loehle-Conger
> MVP SQL Server Reporting Services
> "Konstantin Shaumyan" <KonstantinShaumyan@.discussions.microsoft.com> wrote
> in message news:3A7E2C6B-FF43-4993-9B21-04EA79316410@.microsoft.com...
> >I need to display two charts on a report based on the same stored procedure
> > that accepts a single parameter. I do not wish to be promted for the
> > parameter. Instead, I would like to pass two different values to each
> > chart
> > within the report.
> >
> > Please advise.
> >
> > Thanks,
> > Konstantin
>
>sql

Friday, March 23, 2012

How to use switch - case statement in T-SQL..?

Hi,

I want to use switch - case statement in T-SQL stored procedure.

Can any one help regarding the same..?

for e.g.

switch (exp)

{

case 1 : stmt 1; break;

case 2 : stmt 2; break;

case 3 : stmt 3; break;

& so on.......

}

Hi,

See the following example

DECLARE @.TestVal int
SET @.TestVal = 3

SELECT
CASE @.TestVal
WHEN 1 THEN 'First'
WHEN 2 THEN 'Second'
WHEN 3 THEN 'Third'
ELSE 'Other'
END

how to use stored procedures with Sql Compact Edition

I am working on C# Windows Application and Iw ould like to know j\how can I implement stored procedure with SQL Compact Edition?Stored procedures are not available in SQL CE. For more info on SqlCeCommand limitations, see http://msdn2.microsoft.com/en-us/library/system.data.sqlserverce.sqlcecommand.aspx

How to use stored procedures as the dataset for reports?

Hi,
I want to use a stored procedure as the dataset for a report.
Even though I could execute the stored procedure in the query designer view,
the report designer did not generate the fields list (in the fields window).
Then I specified all the fields explicitly in the fields property of that
dataset. But when I tried to see the report in the preview pane, it gave me
a message that the dataset does not contain the required fields. I verified
the field names and they were exactly matching so no typo out there.
Can anyone tell me how can use a stored procedure as the dataset?
thanks,
NileshThere is a button that looks like the refresh button in IE that if you hover
over it is says refresh fields. Click on that and it will get all the field
information.
Bruce L-C
"Nilesh Oswal" <nilesh_oswal@.persistent.co.in> wrote in message
news:enGR9A3YEHA.3892@.TK2MSFTNGP09.phx.gbl...
> Hi,
> I want to use a stored procedure as the dataset for a report.
> Even though I could execute the stored procedure in the query designer
view,
> the report designer did not generate the fields list (in the fields
window).
> Then I specified all the fields explicitly in the fields property of that
> dataset. But when I tried to see the report in the preview pane, it gave
me
> a message that the dataset does not contain the required fields. I
verified
> the field names and they were exactly matching so no typo out there.
> Can anyone tell me how can use a stored procedure as the dataset?
> thanks,
> Nilesh
>|||After executing the query from the designer, click the refresh button. Your fields should then populate.
Dave
--
Posted using Wimdows.net NntpNews Component -
Post Made from http://www.SqlJunkies.com/newsgroups Our newsgroup engine supports Post Alerts, Ratings, and Searching.

how to use stored proc to drive data-driven subscription

I am wondering how to use a stored proc that, in the procedure, uses TEMP
TABLES to drive the parameters for a data driven subscriptions.
In other words, I want this stored procedure to return a list of e-mail
addresses to distribute the report to. This procedure gathers this list of
addresses, but in order to do so it needs to execute *another* stored
procedure, putting the data from that stored proc into a TEMP table.
When I run the proc in query analyzer it works fine (no surprise) but when I
tell RS to use it as the query for the subscription it gives me the error:
The dataset cannot be generated. An error occurred while connecting to a
data source, or the query is not valid for the data source.
(rsCannotPrepareQuery) Get Online Help Invalid object name '#step1'.
I am setting up the data-drive subscription as follows:
exec rpt_misc_GetLostBillPayments_emailproc_sp
Here is a copy of the above proc:
<snip>
declare @.emails varchar(255)
set @.emails = 'mymail@.myaddress.com;'
create table #step1
(claim_id int,
bill_id int,
received_date_2 datetime,
modified_date datetime,
bill_amount float,
provider_claim_payment_id int,
provider_payment_created_date datetime)
insert into #step1
(claim_id,
bill_id,
received_date_2,
modified_date,
bill_amount,
provider_claim_payment_id,
provider_payment_created_date)
exec rpt_misc_getlostbillpayments_sp
select top 1 claim_id, @.emails as email from #step1
drop table #step1
Any suggestions?You should be able to do this through the SOAP API (read use rs.exe). The
CreateDataDrivenSubscription does not validate the fields you specify, so as
long as the field names returned at runtime match those used in the data
driven subscriptions' field references it should work.
The UI calls PrepareQuery before creating the subscription to get the fields
list. It sounds like you know what the fields are already, so you might be
able to skip this test. Note that this makes the subscription uneditable in
the UI.
-Lukasz
--
This posting is provided "AS IS" with no warranties, and confers no rights.
"david boardman" <davidboardman@.discussions.microsoft.com> wrote in message
news:D5877C1D-596C-4E56-A9DF-98D4CB6000F4@.microsoft.com...
>I am wondering how to use a stored proc that, in the procedure, uses TEMP
> TABLES to drive the parameters for a data driven subscriptions.
> In other words, I want this stored procedure to return a list of e-mail
> addresses to distribute the report to. This procedure gathers this list
> of
> addresses, but in order to do so it needs to execute *another* stored
> procedure, putting the data from that stored proc into a TEMP table.
> When I run the proc in query analyzer it works fine (no surprise) but when
> I
> tell RS to use it as the query for the subscription it gives me the error:
> The dataset cannot be generated. An error occurred while connecting to a
> data source, or the query is not valid for the data source.
> (rsCannotPrepareQuery) Get Online Help Invalid object name '#step1'.
> I am setting up the data-drive subscription as follows:
> exec rpt_misc_GetLostBillPayments_emailproc_sp
>
> Here is a copy of the above proc:
> <snip>
> declare @.emails varchar(255)
> set @.emails = 'mymail@.myaddress.com;'
>
> create table #step1
> (claim_id int,
> bill_id int,
> received_date_2 datetime,
> modified_date datetime,
> bill_amount float,
> provider_claim_payment_id int,
> provider_payment_created_date datetime)
> insert into #step1
> (claim_id,
> bill_id,
> received_date_2,
> modified_date,
> bill_amount,
> provider_claim_payment_id,
> provider_payment_created_date)
> exec rpt_misc_getlostbillpayments_sp
>
> select top 1 claim_id, @.emails as email from #step1
> drop table #step1
>
> Any suggestions?

Wednesday, March 21, 2012

How to use SQL stored proc as datasource for MS Word mail merge?

Is it possible to use a SQL Server stored procedure as a datasource for MS
Word mail merge? If yes then how?
Yes but I believe it depends on what version of Word. You
can use MS Query, select whatever for the tables and then
edit the SQL text in MS Query. You can use something like:
{call YourStoredProcedure}
There is also an OpenDatasource method of the MailMerge
object.
-Sue
On Fri, 6 Aug 2004 14:40:15 -0500, "Fred Zolar"
<fzolar@.yahoo.com> wrote:

>Is it possible to use a SQL Server stored procedure as a datasource for MS
>Word mail merge? If yes then how?
>

How to use SQL stored proc as datasource for MS Word mail merge?

Is it possible to use a SQL Server stored procedure as a datasource for MS
Word mail merge? If yes then how?
Fred Zolar wrote:
> *Is it possible to use a SQL Server stored procedure as a datasource
> for MS
> Word mail merge? If yes then how? *
Have you figured this out? If so, I would be interested as I am
trying to do the same thing.
carolyn01
Posted via http://www.webservertalk.com
View this thread: http://www.webservertalk.com/message340375.html
|||Fred Zolar wrote:
> *Is it possible to use a SQL Server stored procedure as a datasource
> for MS
> Word mail merge? If yes then how? *
I found a way to get this to work. I created a view in SQL Server
placing the SQL in the view instead of the stored procedure. Then I
pointed the Word Merge document to the view. It works. Hope that
helps!
carolyn01
Posted via http://www.webservertalk.com
View this thread: http://www.webservertalk.com/message340375.html

How to use SQL stored proc as datasource for MS Word mail merge?

Is it possible to use a SQL Server stored procedure as a datasource for MS
Word mail merge? If yes then how?
quote:
Originally posted by Fred Zolar
Is it possible to use a SQL Server stored procedure as a datasource for MS
Word mail merge? If yes then how?


Have you figured this out? If so, I would be interested as I am trying to
do the same thing.|||
quote:
Originally posted by Fred Zolar
Is it possible to use a SQL Server stored procedure as a datasource for MS
Word mail merge? If yes then how?


I found a way to get this to work. I created a view in SQL Server placing
the SQL in the view instead of the stored procedure. Then I pointed the Wor
d Merge document to the view. It works. Hope that helps!

how to use SPOOL in a stored Procedure?

How can I use SPOOL Command in a stored procedure to divert the output of a select statement to a file?You can't. You could use UTL_FILE to write to a file on the server. Or, if there is not too much output, you could use DBMS_OUTPUT in the stored procedure and SET SERVEROUT ON in SQL Plus before running it.|||Originally posted by andrewst
You can't. You could use UTL_FILE to write to a file on the server. Or, if there is not too much output, you could use DBMS_OUTPUT in the stored procedure and SET SERVEROUT ON in SQL Plus before running it.
Sorry dear friend by using ref cursor it's possible.|||Originally posted by amit_krai
Sorry dear friend by using ref cursor it's possible.
You think so? OK, if you can make the SQL Plus "SPOOL" command work from a stored procedure using a REF CURSOR, please share your code!|||Well if you mean something like this...
Oracle9i Enterprise Edition Release 9.2.0.4.0 - 64bit Production
With the Partitioning, OLAP and Oracle Data Mining options
JServer Release 9.2.0.4.0 - Production

SQL> CREATE OR REPLACE PROCEDURE procedure_name (
2 column_name IN VARCHAR2,
3 ref_cursor OUT SYS_REFCURSOR)
4 IS
5 BEGIN
6 OPEN ref_cursor FOR
7 ' SELECT SUM (sal), ' || column_name ||
8 ' FROM emp GROUP BY ' || column_name;
9 END;
10 /

Procedure created.

SQL> SET AUTOPRINT ON;
SQL> VARIABLE ref_cursor REFCURSOR;
SQL> SPOOL emp_groups.lst
SQL> EXEC procedure_name ('DEPTNO', :ref_cursor);

PL/SQL procedure successfully completed.

SUM(SAL) DEPTNO
---- ----
8750 10
10875 20
9400 30

SQL>
...then that is not calling SPOOL from a PL/SQL procedure - the stored procedure has finished executing, the output is being SPOOLed by SQL*Plus, not by PL/SQL. Perhaps we are splitting hairs - can the original poster confirm whether this is what they meant?

Padders|||For Spooling, create a batch file and call it into your procedure.

How to use sorting in an "Order by" function

When I run a stored procedure I get a resultant set which contains a field called "Status". This status can be 'Approved','Declined' or 'Withdrawn'.

Now I want to add a parameter('Approved' or 'Declined' or 'Withdrawn') to the stored procedure which is an input from the external user. Based on the user preference I want to sort the output to display.

i.e. if the user selects 'Withdrawn' then the resultant set of the stored procedure must display all the records with 'Withdrawn' status first then the other records.

Currently I am using "Order by status" but unable to understand how to implement the above logic.

Does any one has suggestions or an approach that would be helpful to me?

You can do below in the ORDER BY clause:

ORDER BY NULLIF(Status, @.Your_Parameter)

This will result in NULL if the status matches the passed parameter and status value otherwise. And since NULL values get sorted first in SQL Server those rows will get ordered first.