SQL Server :: Pass A Value Into Procedure And Use As Condition?
Feb 7, 2011
I have a request that allows the end user the option to select a radiobutton with the following values;
>= or <=
and then provide a numerical value in textbox So i would like to know if i can pass in 2 parameters to the procedure.. so that my where statement is built based on the inputs from the user.
Example would be
@conditionvalue
@numericalvalue
SELECT *
FROM mytable
WHERE column1 @conditionvalue @numericalvalue
Whats the best way to accomplish this.. the statement is pretty simple, selecting a few columns and 2 where conditions, the one above and another parameter.
View 13 Replies
Similar Messages:
Jan 28, 2011
Instead of dynamically building an sql to update data based on certain fields that are filled in, I would like to try and do it via a stored procedure I have three fields passing potentially passing to a stored procedure
myCommand.Parameters.AddWithValue("@Field1",
Field1.Text)
myCommand.Parameters.AddWithValue("@Field2",
Field2.Text)
myCommand.Parameters.AddWithValue("@Field3",
Field3.Text)
Stored Procedure accepts 3 parameters
@field1 nvarchar(20), @field2 nvarchar(20), @field3 nvarchar(20)
I want to be able to pass parameters in a variety of ways
field1, field2, field3
or
field1, field3
or
field2, field3
When I attempt thsi, it provides an error of a missing parameter when I do not supply all three. Is there any way to pass exclude parameters at times. The most important thing is that I do not want to update the field to a null when a parameter is not passed, I want it to exclude updating that field altogether
View 6 Replies
Oct 1, 2010
I'm looking to pass a list into a stored procedure, stored as List<myClass>. I've passed a table in before but I'm not sure how to pass a list.
View 1 Replies
Oct 27, 2010
I have "HUGE" stored Procedure... so I just decided to separate this big SP to some small sp ( for easy to maintain)I meet a problem is in SP A
create table #tmp
(
)
select .
from.
// then call sp B
exec B -- would it possible to pass my temp table to SP B? so I can do next operate in SP B
View 5 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
Oct 4, 2010
I would like to take your help for a small task of mine. I have dataset whose contents have been converted as xml, the contents of which needs to be sent to a stored procedure. How do i go about creating methods in the data layer and the stored procedure.What should be parameter type in the data layer's method and what should be the parameter type in the stored proc. I dont want to use a varchar at the stored proc level because it is limited to a length of only 8000 characters.
View 3 Replies
Feb 10, 2011
We have an application we are maintaining, cant make changes to the database, but new form was created and need to pass the values into the table now..
there are 2 columns in the table that are to store the date, but the datatype is set to float.
When i try to pass the values into the procedure in my code behind i get errors that says
"input string was not in a correct format"
my procedure is expecting float, my class method is expecting float, my parameter.add is passing it as float cmd.Parameters.Add("@sdate", System.Data.SqlDbType.Float).Value = sdate;
So im guessing that on my page code behind where im calling the insert method and passing in my textboxes, i need to make some adjustments.. just not sure what they are..
float stDate = System.Convert.ToSingle(txtSdate.Text);
View 3 Replies
Jan 31, 2011
I have one more question. How can I use a column in the stored prcedure and pass it to a parameter in the code above?
Can we access a column like that?
View 23 Replies
Dec 22, 2010
I would like to create a common stored procedure for all insert operations performed in my Database. So i created a stored procedure as below.
[Code]....
But now my problem is how to pass parameters for this stored procedure. I have got the column names of the table passed. But i would like to pass the parameters for each insert operation of each table to identify which value is passed for which parameter.
how to pass parameters for this stored procedure.
(Parameter can be Column name prefixed @ i.e. @Column name)
It is possible to get the column names in another Stored Procedure . But how to prefix @ for each column and pass this as parameter to the Common Insert Stored Procedure?
View 11 Replies
Oct 4, 2010
I am unable to date as dynamic parameter to stored procdure with pivot.i am getting
error
Msg 8114, Level 16, State 1, Procedure Sample, Line 3 Error converting data type nvarchar to datetime. Msg 473, Level 16, State 1, Procedure Sample, Line 3 The incorrect value "@date1" is supplied in the PIVOT operator.
below is my stored procedure
[code].....
View 4 Replies
Dec 30, 2010
In my application I have 7 listboxes.Each list box has morethan 100 listitems.
the best way to pass the selected listitem values(including text values also) to stored procedure in sql server 2005.
View 1 Replies
Jul 17, 2015
I have 3 Textboxes in my Web page. When user key in value in these 3 textboxes,their result should show on a "Label"
1) Gross Amount
2) Taxable Amount
3) Tax Amount
I have to write a Stored Procedure for calculating the value of above textboxes.
Condition is:
If Gross Amount is > or < 0.00, then Taxable and Tax amount should calculate based on below formula:
@TaxableAmt = @GrossAmt / @Rate
@TaxAmt = @GrossAmt - @TaxableAmt
but If Taxable Aount is > or < 0.00, then Gross and Tax amount should calculate based on below forumla:
@GrossAmt = @TaxableAmt * @Rate
@TaxAmt = @GrossAmt - @TaxableAmt
and for "Tax Amount" I have 2 different conditions:
If Tax Amount is = 0.00, then Taxable and Gross amount should calculate based on below formula:
@TaxableAmt = @TaxAmt / (@Rate-1)
@GrossAmt = @TaxAmt + @TaxableAmt
but If Tax Amout is <> 0.00, then whatever the value of Tax Amount is, it should key-in/show as it is.
i.e., @TaxAmt = @TaxAmt
For this requirement, I wrote below SP:
ALTER PROCEDURE [Invoice].[usp_tbl_TaxCode_Update]
-- Add the parameters for the stored procedure here
@TaxCodeID nvarchar(50) ,
@GrossAmt decimal(18, 2),
@TaxableAmt decimal(18, 2),
@TaxAmt decimal(18, 2)
[code]...
But its not working as per required.
View 1 Replies
Mar 7, 2011
I have created one stored procedure which runs on 5000 users in tbluser table with some filter condition in database.There are 4 filtering condition(FC1,FC2,FC3,FC4).Filtering condition has some ListBox and dropdown list of department and countries.I want output as given below:
ID Name StaffNo department Points
1 KK 111 dep1 2
2 NN 222 dep2 1
3 DD 333 dep3 4
I got ID,Name,StaffNo,department in resultset but not points.
points calculation would be based on filtering condition like
if FC1 matched user gained point 1,if both FC1 and FC2 matched user gained 2 point,if both FC1 ,FC2 and FC3 matched user gained 3 point etc.
--in stored procedure i m using dynamic query
DECLARE @SQL VARCHAR(2000)
SET @SQL = 'SELECT U.UserID, U.StaffNo,U.FirstName+'' ''+ U.LastName AS EmployeeName,''?'' AS Points FROM tblUser U '[code]....
all filtering condition are implemented with OR logic.
View 3 Replies
Sep 1, 2010
I am trying to create the following stored procedure in sql server Lat and Lng are the parameters being passed from c# code behind .But I am not able to create this stored procedureit indicates with error saying undefined column name Lat,Lng
CREATE FUNCTION spherical_distance(@a float, @b float, @c float)
RETURNS float
AS
BEGIN
RETURN ( 6371 * ACOS( COS( (@a/@b) ) * COS( (Lat/@b) ) * COS( ( Lng/@b ) - (@c/@b) ) + SIN( @a/@b ) * SIN( Lat/@b ) ) )
END
sqlda.SelectCommand.CommandText = "select *, spherical_distance( Lat, 57.2958, Lng) as distance
from business
[code]...
View 1 Replies
May 13, 2010
I have a page with list box and user can select multiple values from that lst box. Now what I want to do is when user submits the page I want to generate a comma seprated string that contins the ID's of values selected and pass this string to stored procedure. String would look like something like that '2,5,9'
Now my question is how can I split these ids in my stored procedure and get the records based on these ID's. In want to pass this array to Source coloumn in the follwoing Stored procedure and get the data. Right now following stored procedure is working on the basis of single source id passed to it.
[Code]....
View 2 Replies
Jun 5, 2010
var a=conn.getData2();//getting the value from a global class conn.cs
OracleConnection con = conn.s();
OracleCommand oc = new OracleCommand("logedin(I need to pass the value here)", con);
logedin is strored procedure :-
create procedure logedin(user_id in int)
as
begin
update user_details set status='logedin'
where userid=user_id;
end;
i would lke to pass the value into the stored proc that was retrieved by the variable into the database.
View 4 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
Jul 16, 2010
I created a CR which data source is a store procedure. Within the store procedure there is one parameter. How to pass a value to the parameter and display CR on the screen?
View 1 Replies
Jun 22, 2010
I have another post on formatting arrays [URL], thinking that would be the way.. and may be it is.. But let me explain it here and see if thats where i need to focus. I have a class that i use to call 3 different procedures, the values from proc#1 are passed to proc#2 and then proc#2 values passed on to proc#3. Now my problem is that i need the results from proc#3 to be placed in a variable i can pass on to another procedure to execute a query.
Proc#1 returns only 1 record. (easy to place into a session or variable)
Proc#2 returns only 1 record. (easy to place into a session or variable)
Proc#3 returns multple records(its only 1 field that is returned, but can have multiple records), so i need to know what is the best solution to place all records returned into a session or variable to use as a parameter in a query?
Since i need to pass those values to a stored procedure, how can i pass what is returned from proc#3 to my query? One of the parameter of the store procedure is our locations, so my query will look like this:
Select *
From tblName
Where loc LIKE ('1','2','3' )
So i want to set it up so that the values within the LIKE statement are passed in from the page like so
Select *
From tblName
Where loc LIKE (@loc)
View 6 Replies
Jan 11, 2010
I've changed the definition on one of my tables by removing a field from my data key. However, I still want to pass this field to my stored procedure that inserts fields into this table from another table. The field in question is called ignum. I was using the code
[Code]....
View 5 Replies
Jun 19, 2010
I created a stored procedure in my MVC project. I need to execute it and pass result to view form. How can I do this?
View 1 Replies
Feb 17, 2010
how can i pass a session variable in a C# web form to a stored procedure..?
View 1 Replies
Apr 30, 2010
Ive tried a few ways of doing this without success and got together a simplified example so hopefully I can get an answer. When I try to INSERT using a stored procedure InsertTest (normal SQL works OK) I cannot. I need to know how to pass the @Model parameter to the Stored procedure
Have a Stored procedure which can be executed and after entering string for @Model through wizard a new record is created
My asp:SqlDataSource includes InsertCommand="InsertTest" InsertCommandType="StoredProcedure"
Also my <InsertParameters includes the asp:Parameter Name="Model" Type="String"/>
My drop down (and I think this is where the problem is ). Record is Inserted after choosing Model and pressing enter
Do I have to set one of the properties in the drop down to tell the Stored procedure the parameter being passed is the parameter Model ??
[Code]....
View 4 Replies
Feb 7, 2010
.cs code is
[Code]....
and .aspx code is
[Code]....
now i want to pass value in Reply.aspx?C={0} to stored procedure
View 3 Replies
Jan 20, 2010
I have a form that I need to add a new multiple selection criteria. I added a List Box and I populate it on Load. After user selected his choices I need to pass the values to SQL Select stored procedure. I use C# and SQL. I am not sure how to pass the values and write SQL statment that would select records with the selected values. I also have RAD Teleric list box but again the values need to be passed to sql.
View 2 Replies