SQL Server - How to write selected stored procedure

Asked By bhanupratap singh on 20-Nov-12 05:11 AM
I want to write Select stored procedure . But problem is that I need to select data from table which has parameter one .
           
Suppose user selects multiple value in listbox, like:-
Delhi
Mumbai
Kolkata

Then I need to fetch data from table which have user selected. I need this data  in single row to bind the datatable

like
Delhi= 5 students totalfees=5000          
Mumbai= 50 students totalfees=15000

Robbe Morris replied to bhanupratap singh on 20-Nov-12 07:57 AM
If you have SQL Server 2008 or above, you could use table parameters:

http://lennilobel.wordpress.com/2009/07/29/sql-server-2008-table-valued-parameters-and-c-custom-iterators-a-match-made-in-heaven/
help
Query - -> Populate table, keep table parameters DataBase , Populate, table, , keep, table, parameters" / > Hi, I have a select query that is linked to an ODBC database. Each month month the number of account values change and when this is paste into excel the table also changes. Usually the results of the query is 30 rows and 3 columns, but not there it will not be returned by the query. How do we keep the table the same and have account "XYZ" return zero account balance? THanks! Access Discussions Database (1
what is the use of table valued parameters in sqlserver 2008 thanks HI In SQL SERVER 2008 we can use Table-Valued Parameter to send multiple rows of data to a stored procedure or a function without creating a temporary table or passing so many parameters. Table-valued parameters are declared using user-defined table types. To use a Table Valued Parameters
Here I have created a table with 42 columns. . . . but in that i want to insert data in the first 30 int i = 0; i < columCount; i++) { / / Code to generate dynamic controls and insert into the table } } } if you are creating the sql statement dynamically then you can do something like this when preparing sql staements CREATE TABLE test( col1 varchar (10) , col2 varchar (10) , col3 varchar (10) ) DECLARE @sSQL VARCHAR ( MAX ) SET dynamic staement, then by default it would take null value then do like this CREATE TABLE test( col1 varchar (10) , col2 varchar (10) , col3 varchar (10) ) DECLARE @sSQL VARCHAR ( MAX ) SET Andif you think that this solution is not permissable under your program constraints, you add parameters to your command and for all those that are null, explicity assign DBNull.value foreach (IDataParameter param in command.Parameters) { if (param.Value = = null) param.Value = DBNull.Value; } OR like below var valueToBePassed = null; SqlCommand command = new SqlCommand(); command.Parameters.AddWithValue("@valueToBePassed", valueToBePassed?? DBNull.Value); Hope this information helps. I think you have got it
I have a table with text parameters (table 1) and a second table with vlaues that relate to each parameter from table 1 (table 2). I want to design a query that will look up the parameters in table 1 and return the assigned value from table 2. Example of table 1: ID soil
I know how to insert into a table using table parameters, but how do you delete / update with them? SQL Server Programming Discussions Stored procedure (1 1) HeadlineStartDate (1) HeadlineEndDate (1) HeadlineID (1) The same way you would use a regular table to perform delete / update: MERGE INTO TargetTable AS T USING @TableValuedParameter AS S ON T AS T WHERE T.keycol = TargetTable.keycol); - - Plamen Ratchev http: / / www.SQLStudio.com The input table defines the changes that need to be made. Use an SQL MERGE statement or traditional
Can you pass table-valued parameters to table-valued functions? (or any user-defined function)? The first paragraph on http: / / msdn.microsoft.com / en-us / library / bb510489.aspx says you can pass table-valued parameters to a function. Unfortunately, the code sample on that page only shows passing to a example of passing one to a function anywhere on the web. I can successfully pass table-valued parameters to stored procedures, but how do I pass them to functions? Any example
What I'm trying to make is a Union Query that has a field for table names and lets those table names be a parameter. I have figured out how to do parameters (where option), and I have figured out how to do a field for table names ("table name"), but combining the two is beyond me. Any help? Tina KSFC Access Queries Discussions understand what you are attempting to do. Do you expect to use the field for table names in the FROM part of the SQL? - - KARL DEWEY Build a little - Test a
Hi , How can i use table valued Parameter in a store procedure. hi, Table-valued parameters have two primary components: a SQL Server type and a parameter that references that type To create and use table-valued parameters, follow these steps: • Create a table type and define the table structure. For information about how to create a SQL Server type, see http: / / msdn.microsoft
hello team, i am getting this error "Column 'ESIContribution' does not belong to table Table." how to solve this problem please help. This is beacuse of the column name which you are using that is not present in that table. check your column name. and let me know. Hi Please check the Column name in the Table. hi, column name is present in table. even though it is throwing. ok, then check have you selected that column in select the column name is correct Hi, You just simply copy the field name from the table that you have created in the database and paste it in your code. It will
I am trying create a simple report off of a make-table query that I have. The query itself works fine and creates the table. This is the SQL for the Depression Query: SELECT DISTINCT Table1.UniqueID, [Table 10].SatisfiedWithLife, [Table 10].DroppedActivitiesAndInterest Table 10].LifeIsEmpty, [Table 10].OftenBored, [Table 10].InGoodSpirits, [Table 10].AfraidSomethingBadWillHappen, [Table 10].HappyMostOfTheTime, [Table 10].FeelHelpless, [Table 10].PreferToStayAtHome, [Table 10].MoreMemoryProblems, [Table