DataSource Controls :: Assign Value To A Variable From Exec In A Stored Procedure?
Apr 21, 2010
I have this SPDECLARE @PERC VARCHAR(50)
DECLARE @nome_soc_repl VARCHAR(50)
set @PERC = '(select round((' + @nome_soc_repl + ' /(select sum ('+ @nome_soc_repl+ ') from exptot_perc))*100,2)
from exptot_perc)'
EXEC (@PERC)
nome_soc_repl is a varible that contains my table name
so I need to extrac the result of EXEC...for examples 15...... and put it on another variable.....
View 4 Replies
Similar Messages:
Apr 21, 2010
Ive been banging my head against the wall for the last 2 days with this query I am trying to produce. I have an application that creates requests and these requests have status codes dependant on how far along in the process they are : new request, awaiting approval, approved, in progress, complete When a request is moved to the next status, it Inserts a row into an auditing table, so we can track who moved it onto the next status, along with a timestamp. There are Service Level Agreements in place that mean that a request that is currently 'In Progress' must be actioned to 'Complete' within 5 days. I have been asked to create a query that will return all records that fall outside of this SLA. My main problem is trying to Select the time from the audit log for 'In Progress' and 'Complete' status codes. It would be simple if i only had to find one of the times, as i could add a "WHERE StatusCode = 'complete' clause to the query My Audit table is structured as follows:
[RequestID] [Request Status] [UserID] [CreateDate]
So far I have been successful in querying the table by using the DATEDIFF() function as below:
SELECT
DateDiff
(day,
( SELECT
top 1 CreateDate
FROM audit_tblRequest
WHERE RequestStatus
= 'In Progress'
AND RequestID
=
@RequestID Order
by CreateDate
DESC)
,(SELECT
top 1 CreateDate
FROM audit_tblRequestWHERE RequestStatus
= 90AND RequestID
=@RequestID
Order
by CreateDate
DESC)
)
This will return the difference in days to me, however, i cannot figure out how to integrate this into a query that will be run across all RequestIDs. I was wondering if there was any way to bundle the DateDiff function into a stored Procedure and be able to call it For Each RequestID in the result set I would need to pass the requestID as a parameter, and also add some If Else logic to only return records outside of the 5 Day SLA. Im sure there are some patches in the above logic, but my brain is about to explode and I needed to type it all out before calling it a day for today.
View 3 Replies
Aug 7, 2010
I have an aggregate stored procedure (named sp2) that returns a count of records meeting a certain criteria ASrecCount. I am using a DAL per the ASP.NET tutorial and have created a Table Adapter (named
sp2TableAdapter) with GetData and Fill methods. I have a button on an ASP.NET page that launches an event handler. In the button's event handler, I have this line: sp2TableAdapter sp2 = new sp2TableAdapter();
What works so far:
This code will bind the value of sp2 to a data control:
sp2TableAdapter sp2 = new sp2TableAdapter();
DropDownList1.DataSource = sp2.GetData();
DropDownList1.DataValueField = "recCount ";
DropDownList.DataTextField = "recCount";
DropDownList1.DataBind();
When running this page and clicking the button, the numeric value of recCount returned from sp2 is bound to the DropDownList control and 1 row is poplated with the recCount value (in my case 1451).
Problem:
In the event handler, I do not want to bind the value of recCount to a control, but want to to use it in some logic as an integer. What is the C# code that will do this? (In place of the DropDownList control lines above)
View 2 Replies
Jan 18, 2010
I've created a SQL stored proc and want to change it to use a local variable to reduce process time..
Major lines of my SP:
[Code]....
I've been trying to use a variable for AVG(AA.Count) so that I don't have to process it three times,
[Code]....
=> this stored proc does not work, and I am not too sure where I should declare my local variable to use it in SELECT statement..
View 9 Replies
Feb 18, 2010
I've written a stored procedure which uses a table variable. The stored procedure is shown below:
[Code]....
The table variable @CaseNumbers is declared, and is a bunch of values are inserted using a table-valued function called SplitStringIntoInts. At this point I can select from @CaseNumbers and this works fine.But when I try to join onto @CaseNumbers, the name '@CaseNumbers' in the ON clause is highlighted with the error 'Must declare scalar variable @CaseNumbers'. What?! It's not scalar, I declared it ages ago and I have used it since!
View 3 Replies
Jun 22, 2010
Is it possible to save execute stored proc command in a string variable and then execute string variable?
Does this logic fits into LINQ2SQL? Why I want to do this - INstead of passing user control references to server, I want to save user control values to string in client side java script and then pass string to server to do actual stored proc execution. Hopefully this will improve performance.
View 3 Replies
May 19, 2010
Here's a stored procedure I created that uses another stored procedure inside it to return a value:
[Code]....
Note the 'exec dirinfo.dbo.d_searchempbyname @TicketSubName' part. That stored procedure will return a single record. What I need is to get a single column from that recordset (in this case, the email address of the employee), and store that value in a variable.
View 3 Replies
Apr 2, 2010
This is surareddy. i nead some small clarification in the "Stored Procedure"
how to convert the oracle Stored Procedure to sqlserver2005/2008 Stored Procedure.
right now i am enhancing the project that project already developed the oracle Stored Procedure. now our company is using sqlserver 2005/2008.
how to convert the Oracle Stored Procedure to sqlserver 2005 Stored Procedure
View 4 Replies
Dec 9, 2010
Initially, I have tried to use stored procedure. But I changed my mind and preferred to call sql query in codebase with command text. However, it stills tries to find initially-called stored procedure (which is neither called or exists).I think that it is related caching. But I tried it with different browsers it did not work.What might be the reason?
View 4 Replies
Jan 18, 2010
Does anybody if it is possible that a stored procedure returns rows which is the result of the execution of another sp? Something like..
[Code]....
View 11 Replies
May 13, 2010
i want to return output parameter from 1 storeprocedure. into another stored procedure.
View 7 Replies
May 1, 2010
I want to apply other stored procedure select query on result of first stored procedure.
View 1 Replies
Apr 27, 2010
I am using Visual Studio 2008 and SQL Server 2008 and have added a SQL datasource to my form.
When I configure the datasource, I choose my connection string which looks like this in my webconfig:
<connectionStrings>
<add
name="PSFSPRD_ConnectionString"
connectionString="Data
The database I am using has a schema called EQB and as such, my stored procedures are named as EQB.usp_SelectFunds, EQB.usp_SelectAccount, etc.
On the select tab of the Configure Data Source screen, I choose to use a stored procedure. The dropdown shows my stored procedures, however, the schema name does not show up in front of the stored procedures in the drop down. I see only usp_SelectFunds, usp_SelectAccount, etc.
I select one of the stored procedures and when I click TEST, I get the message that the stored procedure is not found. If I instead choose to use a SQL statement instead on the configuration screen and enter EXEC EQB.usp_SelectFunds and click TEST, it works fine.
Why are my stored procedures not showing up correctly in the stored procedure drop down and how can I fix this?
View 3 Replies
Sep 7, 2010
I am calling a stored procedure, that exists in a SQL Server 2005 database, using ADO.NET, in which I instantiate a sql command object.
The stored procedure has an ouput variable like '@packageCode VARCHAR(100) = NULL OUTPUT'.
Can I set it's value when creating the sql command object? Or I can never set a value for an output type variable in a stored procedure?
View 5 Replies
Feb 16, 2011
I have this procedure
[Code]....
I don't know what variable should be put in where clause for tblVisitor.visitorID because there's a variable that was already passed by an output identity parameter by a different stored procedure. What will I put in the where clause for visitor id?
View 3 Replies
May 30, 2010
how to use stored procedure in asp.net for for manipulation form sql server (in details).
View 2 Replies
Mar 31, 2010
parameters inside the stored procedure.How to write .
View 6 Replies
Sep 26, 2010
I want to send an image to a stored procedure variable that is varbinary(max) field, It works correctly when an image selected by fileupload and my image property has image file, and it can send to stored procedure. but when fileupload is empty I want to send NULL to stored procedure variable that is varbinary(max). I use DbNull.Value in C# code. But error occurs. What should I do for send Null to stored procedure?
View 3 Replies
Jan 10, 2011
here my code-
using (SqlDataReader sqlDataReader = ExecuteReader(CommandType.StoredProcedure, StoredProcedures.AuthenticateUser, sqlParameter))
{
isAuthenticated = Convert.ToBoolean(sqlParameter[2].Value);
if (isAuthenticated)
{
if (sqlDataReader.Read())
{
User = new UserEntity();
DbHelper.GetEntity(sqlDataReader, User);
}
}
}
I always get isAuthenticated as false because sqlParameter[2].Value is null all the time but when I execute my query with ExecuteNonQuery it gives me the value but in that case I can not fill the entity.
View 1 Replies
Aug 20, 2010
If I have the inventory class and want to make it to be xml and passed to web services and then web services will call stored procedure with xml as input parameters.
how to do in coding?
View 3 Replies
Feb 27, 2011
I have a SQL stored procedure on a SQL server that uses a variable to create a new database. This works in SQL I have a connection string that works I have added a sqldatasource to a webform, and configured the datasource to connect to the remote SQL database and am able to select my stored procedure. I am able to bind the variable to a control in the sqldatasource wizard (often two of the same control appear- if that is significant)
When I test the sqldatasource in the configuration wizard and put in a manual entry, the procedure runs and works
It is on the web page I am having troubles. I want the user to enter a name in a text box, click a button/link, and run the procedure. Ive used buttons and links...but not in the right way I think, becuase when I click them the stored procedure doesnt run.
As mentioned above, I have selected the right control in the sqldatasource wizard. So what do I need to do now?
Is it button click event? If so whats the syntax?
Should I be embedding my textbox in a dataview?
View 4 Replies
Sep 9, 2010
My stored procedure expects a uniqueidentifier as a parameter. However, this unique identifier is stored in a table variable, which looks like this:
DECLARE @GiftGuid uniqueidentifie
View 14 Replies
Jun 17, 2010
I created a database on SQL Server 2005 developer edition with MS SQL Server Mangement Studio Express. Now I created code that accessess a stored procedure named 'pS_TableData'. However I have one problem the code raises an exception "Could not find stored procedure 'pS_TableData 'Letters''."the code looks like this:
[Code]....
Note I am using (for now) the same connection that I used to create my database so in essence my web site is the administrator. I tried a simple SELECT from a table with the same connection and it raised no exceptions!When I run EXECUTE ps_TableData 'Letters' in SSMS it has no . I also tried EXECUTE ps_TableData 'Letters' as the command paramated for SqlCommand but it had the same effect
View 1 Replies
May 15, 2010
I call this stored procedure with a dataset. It always returns a 0 but should return a 1 or 2. Does anybody know why it isn't returning a 1 or 2.
ALTER PROCEDURE dbo.sp_InsertLinkVote
@LinkId int,
@LinkVoter nvarchar(50),
@LinkVotesDateTime datetime,
@LinkVotesGoodBad bit
AS
/* SET NOCOUNT ON */
If EXISTS
(SELECT
*
FROM
LinkVotes
WHERE
LinkId=@LinkId
and
LinkVoter = @LinkVoter )RETURN
1
ELSE
INSERT INTO
dbo.LinkVotes (LinkId,LinkVoter,LinkVotesDateTime,LinkVotesGoodBad)VALUES
(@LinkId,@LinkVoter,@LinkVotesDateTime,@LinkVotesGoodBad)RETURN
2
Here is were a call it in my code behind.
Dim VoteCheck
As
Integer
Dim InsertVote
As
New DataSetStoredProceduresTableAdapters.QueriesTableAdapter
VoteCheck = InsertVote.sp_InsertLinkVote(LinkId, User.Identity.Name, DateAndTime. Now,
True)
'0 is a good vote.
If VoteCheck = 0
Then
It seems to insert and not insert correctly, I just cannot get it to return the correct value.
View 4 Replies
Jun 23, 2010
I am developing a page in ASP.Net where I have the user enter a letter into a textbox. They then click a submit button and I all of the userids that start with that letter are to be displayed. So I need the SP to go through the database and match first letters with what was entered. Here is what I have as my code for the SP:
CREATE PROCEDURE dbo.exp2 @testchar Char(1)
declare @flag as char(2)
set @flag = @testchar + '%'
select userid
from ex_database
where userid like @flag
View 6 Replies