How To Return Value From Dynamic Query Or Set The Value

Nov 28, 2007

Hii I am Varun  i have a problem with the dynamic stored procedure

This is my stored procedureALTER PROCEDURE dbo.sp_TimeTableAdjustment1

(@TeacherID_OnLeave numeric(9),

@DateFrom datetime ,@DateTo datetime , @UserID numeric(9)

)

AS

declare @flag as numeric(9)

declare @year as varchar(4)

set @year=(select batch from batchmaster where iscurrent=1 and isdeleted=0)

if( @year=null or len(@year)=0)

set @year = year(getdate())exec ('if not exists(select * from timetableadjustments_'+@year+' where datefrom='''+@datefrom+''' and dateto='''+@dateto+''' and teacherid_onleave='+@teacherid_onleave+')

begin

insert into TimeTableAdjustments_'+@year+' (TeacherID_OnLeave,DateFrom,DateTo,UserID) values ('+@TeacherID_OnLeave+','''+@DateFrom+''','''+@DateTo+''','+@UserID+');

end')

else

set @flag=(select timetableadjustmentid from timetableadjustments_2007 where datefrom=@datefrom and dateto=@dateto and teacherid_onleave=@teacherid_onleave)

return @flag

--exec('select timetableadjustmentid from timetableadjustments_'+@year+' where datefrom='''+@DateFrom+''' and dateto='''+@DateTo+''' and teacherid_onleave='+@TeacherID_OnLeave+'

--')

--return @flag

--exec('@flag=select timetableadjustmentid from timetableadjustments_'+@year+' where datefrom='''+@DateFrom+''' and dateto='''+@DateTo+''' and teacherid_onleave='+@TeacherID_OnLeave+'')

View 1 Replies


ADVERTISEMENT

Transact SQL :: Use Dynamic Table Names And Get Return Value From The Query

Sep 16, 2015

I don't know why this is so difficult. What I want to do is take a table name as a parameter to build a query and get an integer value from the result of the query. But from all of the research I have been doing, Dynamic SQL is bad in SQL server because of SQL Injections. But my users are not going to be supplying the table names.

Things I have learned:

 - SQL Functions cannot use Exec to execute query strings.
 - SQL Functions can return a concatenated string that could be used by a stored procedure to Exec the query string.

So how can I write a stored procedure that will
 
1. take a parameter
2. Pass the parameter to a function that will return a string
3. Execute that string as SQL
4. Get a return value from that SQL statement
5. Then finally, from a View, how can I pass a parameter to the stored procedure and get the returned value from the stored procedure to be used as a field in the View?

Numbers 3, 4, and 5 are where I am really stuck. I guess I don't know the proper syntax and limitations of SQL Server.

View 14 Replies View Related

Return Value - Dynamic SQL

Nov 20, 2006

I need to get a return value from a sproc. I know how to do it this way:

CREATE PROCEDURE A_SPROC (
@RETVAL REAL OUTPUT
)
AS
SET @RETVAL=(SELECT A_VALUE FROM A_TABLE)
RETURN @RETVAL
GO


What if I am using dynamic SQL? How do I set @RETVAL?

View 4 Replies View Related

Using A UDF To Return Values For A Dynamic WHERE IN () Clause

Mar 2, 2006

Greetings,

I've search around quite extensively on the net and found a few examples that touch on this subject, but the only definitive one that seemed to solve this problem used a temp table in the UDF, which, to my knowledge, is impossible...

The problem is thus:
I want to create either a stored procedure or a user defined function to return a list of values I can intersperse to use in a WHERE AccountID IN (<values>). This way, if someone were to create a new stored procedure and they wanted to either only select accounts with those IDs or perform a NOT IN and use it to filter.

The Solution I'm attempting:
My idea is best represented in psuedo-code:
- Create a Function that stores all account Ids we relate to a particular account type, in this case, let's say accountsids "100, 101, 102, 407" are all accounts we want to consider "cash".
- The function would look something like:
CREATE FUNCTION CashAccountIDs()

RETURNS TABLE

AS

BEGIN
DECLARE TABLE @t1 (account INT)
INSERT INTO @t1 VALUES (100)
INSERT INTO @t1 VALUES (101)
INSERT INTO @t1 VALUES (102)
INSERT INTO @t1 VALUES (407)
RETURN @t1
END

Then I could call this function by doing something such as:

SELECT *
FROM Accounts
WHERE AccountId IN (dbo.CashAccountIds())

I would presumably do this for other collections of accounts as well, so that I would end up with say 5 functions I could call to filter various types of accounts.

Not too certain if I am approaching this the correct way or not, I've been receiving a myriad of errors trying different methods. If I use the function above it tells me "Must declare @t1", so I modified it so @t1 is declared in the RETURNS statement, and the syntax checks then work, but when I attempt to save the function it tells me "Cannot perform alter on fn_cashaccountids because it is an incompatible object type"

(The code I use to generate this error is:
CREATE FUNCTION fn_cashaccountids ()

RETURNS @t1 TABLE (i INT)

AS

BEGIN
INSERT INTO @t1 VALUES (100)
RETURN
END

Hopefully I've provided enough but not too much info to sift through, it seems to me this would be something encountered a bit before.

Any help is very much appreciated.

- Jeff

View 3 Replies View Related

Dynamic Sql Inside Function And Return Value

Apr 10, 2007

Is it possible to write dynamic sql on scalar function and assign the value to return value? I like some thing like below but it is not working...
Thanks
______________________________________________________________________
set @sql = 'select @CallLegKey= min(calllegkey) as CallLegKey
from rt_'+@platform+'_CallLegs
where datediff(day,convert(datetime, CallEndTime) ,'''+cast(@today as varchar(20))+''') = '+cast(@cutoff as varchar(5))
exec @sql

return @CallLegKey

View 3 Replies View Related

Dynamic SQL Return Table Variable

Nov 2, 2007

Is it possible in SQL 2000 to return a table variable from dynamic sql? We need to have some code that looks kind of like this:

declare @qry varchar(8000)
declare @sourcetable varchar(100) -- name of source table
declare @mytable table (ID_Num int identity(1,1), Child_Key varchar(100))

set @sourcetable = (select tablename from tblConfig where app = 1)

set @qry = 'insert into @mytable


select * from @sourcetable'

execute (@qry)





if (select count(*) from @mytable) > 0
begin

'insert into myFinalTable

select * from @mytable where blah blah blah



I can get the first part to work by declaring the table variable (mytable) in the dynamic sql, but I can't figure out how to return the table object.

View 7 Replies View Related

Transact SQL :: Return Recordset From Dynamic Table

Sep 25, 2015

I tried to create a dynamic table, fill in it and return it as recordset. The codes as this:

Declare @tbl Table(id int, name varchar(100), age int) 
Insert Into @tbl(id, name, age)
Values(1, 'James, Lee', 28),
   (2, 'Mike, Richard', 32),
   (3, 'Leon Wong', 29)
Select * From @tbl Order By age

It works well in "SQL Query Ananizer". But return no records in ASP page.

View 5 Replies View Related

PIVOT To Return Dynamic Rows Horizontally

Jan 13, 2008

Hi,

I have a client with the following table structure:
ItemNumber, Name, Description

containing the following Data (example):






ItemNumber

Name

Value


6473764

SDRAM

4GB


6473764

Xeon

2300 Mhz


6473764

Video

256 MB


6473764

Bus

1300 Mhz


6473759

SDRAM

2GB


6473759

Xeon

2000 Mhz


6473759

Video

128 MB


6473759

Bus

1066 Mhz

I am trying to use PIVOT to convert this into Columns:






Item Number

SDRAM

Xeon

Video

Bus


6473764

4GB

2300 Mhz

256 MB

1300 Mhz


6473759

2 GB

2000 Mhz

128 MB

1066 Mhz

The problem is that I do not know the names of the columns before I run the query. I retrieve them based on a a list of Item Numbers:
SELECT DISTINCT Name FROM TableName WHERE ItemNumber IN (...)

What I was trying to do is the following, but I am not exactly sure what is wrong:

WITH ProductLines (ItemNumber, ItemName, ItemValue)
AS
(
SELECT ItemNumber, Name, Value FROM ProductItems WHERE ItemNumber IN (...)
)

SELECT * FROM ProductLines -- Don't know the column names
PIVOT
(

... -- Not sure what should come here
FOR ItemNumber IN (...)
)

Thanks a lot,

Aric Levin




View 3 Replies View Related

SQL Server 2012 :: Dynamic Return Type In A Function

Mar 3, 2015

I have created a function that will check whether the data is null or not. If its null then it will display that as No data else it will display the original value. Below is the function

GO
Object: UserDefinedFunction [dbo].[fnchkNull] Script Date: 3/4/2015 12:01:58 PM ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO

[code]...

The code is working good. However i want the return type to be dynamic. If the data type supplied is integer then i want to return a integer value like 0 if its null. if the data value is varchar then i want to return 'No Data'.

View 7 Replies View Related

Dynamic Function To Return Number Of Records In Table

Aug 5, 2014

I want to write a function, which accept 3 parameters, 1 TableName 2 ColumnName 3 DateValue, and returns number of records in that table for that particular date(in parameter date), I have written below function but it is not returning the desired result.

CREATE FUNCTION dbo.[f_Rec_cnt]
(@InTableName NVARCHAR(100),
@InDtColName NVARCHAR(50),
@InDate NVARCHAR(50)
)
RETURNS INT

[Code] .....

View 1 Replies View Related

Dynamic SQL Generation For The UpdateCommand Is Not Supported Against A SelectCommand That Does Not Return Any Key Column Information.

Feb 1, 2007

Hey,
I changed the database name in the initial cataloge in the web.config conncetion string so that it now connects to other databas that contains same tables as the old one,but now i am getting that error at the update stmt !
thank u in advance
Hiba

View 1 Replies View Related

SQL Server 2012 :: Create Dynamic Update Statement Based On Return Values In Select Statement

Jan 9, 2015

Ok I have a query "SELECT ColumnNames FROM tbl1" let's say the values returned are "age,sex,race".

Now I want to be able to create an "update" statement like "UPATE tbl2 SET Col2 = age + sex + race" dynamically and execute this UPDATE statement. So, if the next select statement returns "age, sex, race, gender" then the script should create "UPDATE tbl2 SET Col2 = age + sex + race + gender" and execute it.

View 4 Replies View Related

Return Result From One Query As A Column In Other Query

Jun 3, 2004

I'm having a bit of a trouble explaining what I'm trying to do here.

I have 3 "source" tables and a "connecting" table that I'm going to use

tblContacts - with contactID, ContactName etc
tblGroups - with GroupID, GroupName
tblSubGroups - with SubGroupID, GroupID and SubGroupName (groupID is the ID for the parent Group from tblGroups)

They are related in a table called
tblContactsGroupConnection - with ContactID, GroupID and SubGroupID

One contact can be related to many subgroups.
What I want is a list of all contacts, with their IDs, names and what groups they are related to:

ContactID, ContactName, [SubGroupName1, SubGroupName2, SubGroupName3]
ContactID, ContactName, [SubGroupName1, SubGroupName3]
ContactID, ContactName, [SubGroupName3]

I'm sure there's a simple solution to this, but I can't find it. Any help appreciated. :)

Kirikiri

View 1 Replies View Related

How To Make The SSMSE To Return Whole Records Without Any Close Query Form And Re-create Query Form Operation?

Dec 25, 2007

Hi,
I got a problem.
I installed Microsoft SQL Server Management Studio Express 2005 version.
And I created a Compact database.
I created an connection in SSMSE to connect the database and opened a query form.
then, i run the following sql:

Select * from Table1

It returned 3 records to me.
After that, I used program to insert record into this table.
Then i ran this sql again, it still show me 3 records.
I closed the query form, and re-created a new query form, then run the sql, it returned 4 records to me.

Why? It's very strange and difficult to operate, right?
Is there anyone know how to make the SSMSE to return whole records without any close query form and re-create query form operation?

Thanks a lot!

And Merry X'max!!!

View 4 Replies View Related

Return From A Query

Sep 11, 2005

Hi

How can I know whether a query or a stored procedure is successfully executed? I mean like in delete case?
here is an example

sql_delete = "DELETE FROM UserData where U_ID='" & tempID & "'"
rstIDChk.Open sql_delete, cnn, adOpenStatic, adLockOptimistic


How can I make sure that the record is deleted so that I can proceed with other jobs? How can I catch it in the program like from VB? Is there any return like true or false in SQL? :(

Tks alot..

View 2 Replies View Related

Return A Value After Insert The Query

Oct 8, 2007

Hi!   create table testReturn(id int identity(100,1),name varchar(10)) How can I return the value of identity column after inserting the value.          Dim objConn As SqlConnection        Dim SQLCmd As SqlClient.SqlCommand        Dim ds As New DataSet        Dim strsql As String        Try            objConn = New SqlConnection            objConn.ConnectionString = _                "Network Library=DBMSSOCN;" & _                "Data Source=localhost;" & _                "Initial Catalog=mydb;" & _                "User ID=userid;" & _                "Password=pass"            objConn.Open()            strsql = "insert into testReturn values ('a')"            SQLCmd = New SqlClient.SqlCommand(strsql, objConn)            Dim rowsAffected As Integer = 0            rowsAffected = SQLCmd.ExecuteNonQuery            Dim rv As String            rv = SQLCmd.Parameters(0).Value.ToString()            Response.Write(rv)                    Catch ex As Exception            Response.Write(ex.ToString)        End Try  

View 5 Replies View Related

Need Help Getting A Return Value In SQL Query Analyzer

Jan 17, 2008

This has got to be a simple one, but I could not find out how
I have this simple proc for test purposes only...
 
ALTER    PROCEDURE dbo.RotoTest( @strSSN VARCHAR(11), @blnUseACHDate BIT = 0,  @intInvestorId int = 0)ASreturn 5
 
Thats right it does nothing but return 5 and thats because I removed all the real code to simplify my question.
When I hit this proc in SQL Query Analyzer..
exec RotoTest '123-45-6789', 0, 1     No return value is displayed in Query Analyzer.
When I try something like this
exec RotoTest '123-45-6789', 0, 1, intRetValue Output    (in this situation I get wrong number of arguments)
How can I get a return value displayed on my screen in SQL QUERY ANALYZER with out modifying the proc?  I do not want to modify the proc in anyway (because I can't), I just want to display the return value
 

View 2 Replies View Related

Query Doesn't Return 0

Jun 6, 2008

Hi
 I have written a query for viewing the results of an on-line survey. I have three tables involved in this query: answers, answerpossibilities and users. So I use a few joins and made this query:
ALTER PROCEDURE dbo.GeefAntwoordenMeerkeuze ( @question_id int ) AS SET NOCOUNT ON; SELECT answerpossibilities.answerpossibility_content AS[Answerpossiblity], COUNT(answers.answers_id) AS [Times chosen] FROM answers right OUTER JOIN answerpossibilities ON answers.answerpossibility_id = answerpossibilities.answerpossibility_id left join users on answers.user_id = users.user_id WHERE ((answerpossibilities.question_id = @question_id AND nswerpossibilities.answerpossibility_content!='-- choose answer --')) GROUP BY nswerpossibilities.answerpossibility_content ORDER BY [Times chosen] desc
The above query works fine. The data returned by this query is shown in a gridview. When an answerpossibilty was never chosen it shows 0 as times chosen. So that's fine. But the problem is, only answers of users who completed the survey should be shown. In the users table there's a field user_completed. So the query should check whether this field is 1 (true).
ALTER PROCEDURE dbo.GeefAntwoordenMeerkeuze ( @question_id int ) AS SET NOCOUNT ON; SELECT answerpossibilities.answerpossibility_content AS[Answerpossiblity], COUNT(answers.answers_id) AS [Times chosen] FROM answers right OUTER JOIN answerpossibilities ON answers.answerpossibility_id = answerpossibilities.answerpossibility_id left join users on answers.user_id = users.user_id WHERE ((answerpossibilities.question_id = @question_id AND nswerpossibilities.answerpossibility_content!='-- choose answer --') and users.user_completed = 1) GROUP BY nswerpossibilities.answerpossibility_content ORDER BY [Times chosen] desc
Using this query only answers of users who completed the survey are shown but answer possibilities that were never chosen are no longer shown with 0 as times chosen. The gridview simply doesn't show them anymore.
Thanks for helping me!
 
Something went wrong by posting this message I guess, all blank lines were gone.. maybe because I used Safari on my iMac

View 1 Replies View Related

How Many Rows Will A Query Return?

Apr 8, 2006

Does sql server have a mechanism (aside from count()) that for any given SELECT query will tell you only how many rows it will return without actually returning the data?

The reason for this is that we have a generic lookup form in an application that is used on almost every screen (we have a lot of screens, so it gets a lot of different, sometimes complicted, queries passed to it to use for the lookup, and having to manually edit the query to use count over all the select clauses doesn't seem like the best way to handle this. If we could do a kind of 'trial run' against the server just to get the number of rows and use that to help set up the form, that would be ideal.

View 3 Replies View Related

Query Which Should Return All The Dates Between 2

Jul 20, 2006

i want a query which returns all the date between 2 dates . its like an calender.....for example i selected 2-1-2006(dd-mm-yyyy) to 18-03-2006 ....it should returns like this
2-1-2006
3-1-2006
4-1-2006
.
.
.
16-03-2006
17-03-2006
18-03-2006

View 1 Replies View Related

Return Percentages In The Query.

Oct 13, 2006

Hello,I'm trying to something that just works in Oracle, but does not in SqlServer.How can I get the percentage of two counts to be returned on each rowof the query?select count(sid), /* all not the not null */count(*),(count(sid) /count(*) ) as percent_not_null,4 as four,(3/4) as three_over_fourfrom dbo.sysusers7082040Incredibly, it changes even 3/4 into a zero!For efficiency, I want the percentage returned in the query.And to not use variables and coding. Efficiency,both of the server, and of my time.Note: I am using dbo.sysusers as an EXAMPLE only. My realquery will be on user defined application tables.What is the solution please?

View 4 Replies View Related

Query Help: Need To Return 2nd From Top Record

Jul 20, 2005

i need to retrieve the most recent timestamped records with uniquenames (see working query below)what i'm having trouble with is returning the next-most-recent records(records w/ id 1 and 3 in this example)i also need to return the 3rd most recent, 4th, 5th and 6th most recent- i figure if i can get the 2nd working, 3rd, 4th, etc will be cakethanks,brett-- create and populate tabledrop table atestcreate table atest(id int not null, name char(10), value char(10),timestamp datetime)insert into atest values (1,'a','2','1/1/2003')insert into atest values (2,'a','1','1/1/2004')insert into atest values (3,'b','2','1/1/2003')insert into atest values (4,'b','3','1/1/2002')insert into atest values (5,'b','1','1/1/2004')-- select most recent records with distinct "name"sselect a.* from atest as awhere a.id = (select top 1 b.id from atest as bwhere b.name = a.nameorder by timestamp desc )/*query results for above query (works like a charm)2a 1 2004-01-01 00:00:00.0005b 1 2004-01-01 00:00:00.000*/

View 6 Replies View Related

Query That Return Nulls

Mar 1, 2008

This is my problem, i have 2 tables: one table that hold data, having id as identity, say table (id, content), the other table have 2 columns: (id, number). The second table number column refer to the id in the first table. i want to build a query that get the data from the first table that correspond to a specific id in the second table, not only this i want to get the previous, the current and the next item.

For example: if table_data, table_info is first and second tables, something that can do it is :

DECLARE @i int

SELECT * FROM table_data WHERE id in (@i -1, @i +1, @i)

The problem here if @i, @i+1 or @i-1 doesn't exist the column will not be returned, i want to get a result similar to

id, content

25 null
26 null
27 #some content#

or

34 #content1#
35 #content2#
36 #content3#

so my problem is that nulls doesn't appear, i thought about using OUTER JOIN, but the problem is that outer join take tables, not (@i -1, @i +1, @i), so if only i can make somehow the outer join use these values, i think it works.

Any help please, and thanks in advance

View 6 Replies View Related

How Make MDX Query Return Something Rather Than Nothing?

Sep 28, 2007

Hi


I have encountered some problems creating MDX query.
There are two input parameters on report, both dropdown list and from query.
The first parameter will check "State", and the second parameter "Store Name" depends on previous' result.
If there's no "State" found, I manage to show a "No Data" in the "State" droplist.
But with "No Data" in first parameter, the second parameter simply is not enabled.
I want the second parameter shows " No Data" as well but not succeed.


Here's code

...

SELECT {[Measures].[A1], [Measures].[B1], [Measures].[C1]} ON COLUMNS ,

[Store].[Store Name].ALLMEMBERS ON ROWS
FROM ( SELECT ( STRTOSET(@State) ) ON COLUMNS FROM [Cube])
...
The query need to look at dataset that contains [store name] on rows, and some measures on columns.
It also restricted by parameter @State.

Store Name that satisfies @State will be displayed.
But if nothing from SELECT ( STRTOSET(@State) ) ON COLUMNS FROM [Cube], there's nothing in result.
I'd rather like show something rather than nothing.
I try codes like
...
MEMBER [Store].[Store].[NA] AS '"N/A"'
IIF(<Parameter empty>,
(SELECT ... ON COLUMNS, [Store].[Store].[NA] ON ROWS FROM ...),
(SELECT ...<Original statement >)
)
...
It shows "Subselect support only Column axis".

Any one has an idea?
Please help me out
Many thanks!


Mr. L


View 1 Replies View Related

Dynamic (on The Fly) Query

Jun 20, 2006

Hi all.  I'm currently encountering a problem in attempting to find a solution for a dynamic or on the fly query.  I understand how you can make a static query and return it as a dataset; for example, say you have a field where a user enters a name on the front end and the db returns the results:
Dim queryString As String = "SELECT [Table].* FROM [Table] WHERE ("& _                                "[Table].[Name] = @Name)"
But what if I have multiple items I would like query based upon what the user picks.  For example, say you have five fields: Name, ID Number, Date, Address, and State.  Say the user wants to pick all data with a date between Jan. 06 to April 06, with the name of Tom, and in the state of CA.  But then next time, the user only wants all data with the name of Susan.  So the query is always changing and I am not sure exactly how to go about it.  I guess I sorta want similiar functionality as that of the Custom Auto Filter in Excel.  I've been reading a couple of the forums and I think people are using a string to pass to query the database.  But I am still vague on how to approach this.  Any help would be greatly appreciated!

View 5 Replies View Related

Dynamic Query

Sep 14, 2007

I am having trouble wrapping my head around some dynamic queries.  I have x number of queries stored in a table.  Each row in this table has a From, Join, and Where column.  So, for x=3, I can run the query from each row so that I may have
Q1:  (1, 2, 4, 5, 7, 8)
Q2:  (1, 3, 5, 7, 9)
Q3:  (2, 4, 6, 8, 10)
I need to use these queries to generate a shared table: |-------------------|
| ID | Q1 | Q2 | Q3 |
| 1 | 1 | 1 | 0 |
| 2 | 1 | 0 | 1 |
| 3 | 0 | 1 | 0 |
| 4 | 1 | 0 | 1 |
| 5 | 1 | 1 | 0 |
| 6 | 0 | 0 | 1 |
| 7 | 1 | 1 | 0 |
| 8 | 1 | 0 | 1 |
| 9 | 0 | 1 | 0 |
| 10 | 0 | 0 | 1 |
|-------------------| I'm not sure the best way to do this.  I think that doing it on the asp.net side will be easier than in t-sql, although I am exploring both possibilities.  Any suggestions?

View 13 Replies View Related

Dynamic In SQL Query

Jun 9, 2008

Hi..
I want to change the SQL Query Dynamically .... 

 i have attached the Source code.....1st Page: <%@ Page Language="C#" AutoEventWireup="true" CodeFile="ConsIndex.aspx.cs" Inherits="Cons_ConsIndex"    MasterPageFile="~/MasterPage.master" %><asp:Content ID="Content1" ContentPlaceHolderID="ContentPlaceHolder1" runat="server">    <asp:FormView ID="FormView1" AllowPaging="false" DataSourceID="sqldatasource1" Width="80%"        runat="server">        <ItemTemplate>            <table align="left">                <tr>                    <td>                        <a id="href1" href="consA-Z.aspx?cons=A" target="_self">A </a>                    </td>                    <td>                        |</td>                    <td>                        <a id="A1" href="consA-Z.aspx?cons=B" target="_self">B </a>                    </td>                    <td>                        |</td>                    <td>                        <a id="A2" href="consA-Z.aspx?cons=C" target="_self">C </a>                    </td>                    <td>                        |</td>                    <td>                        <a id="A3" href="consA-Z.aspx?cons=D" target="_self">D </a>                    </td>                    <td>                        |</td>                    <td>                        E</td>                    <td>                        |</td>                    <td>                        F</td>                    <td>                        |</td>                    <td>                        G</td>                    <td>                        |</td>                    <td>                        H</td>                    <td>                        |</td>                    <td>                        I</td>                    <td>                        |</td>                    <td>                        J</td>                    <td>                        |</td>                    <td>                        K</td>                    <td>                        |</td>                    <td>                        L</td>                    <td>                        |</td>                    <td>                        M</td>                    <td>                        |</td>                    <td>                        N</td>                    <td>                        |</td>                    <td>                        O</td>                    <td>                        |</td>                    <td>                        P</td>                    <td>                        |</td>                    <td>                        Q</td>                    <td>                        |</td>                    <td>                        R</td>                    <td>                        |</td>                    <td>                        S</td>                    <td>                        |</td>                    <td>                        T</td>                    <td>                        |</td>                    <td>                        U</td>                    <td>                        |</td>                    <td>                        V</td>                    <td>                        |</td>                    <td>                        W</td>                    <td>                        |</td>                    <td>                        X</td>                    <td>                        |</td>                    <td>                        Y</td>                    <td>                        |</td>                    <td>                        Z</td>                    <td>                        |</td>                </tr>            </table>        </ItemTemplate>    </asp:FormView>    <asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="False" CellPadding="3"        DataKeyNames="consid" DataSourceID="sqldatasource1" Width="100%" AllowSorting="true">        <Columns>            <asp:BoundField HeaderText="consid" Visible="False" />            <asp:TemplateField SortExpression="consid">                <ItemTemplate>                    <p align="left" style="font-family: Arial; font-size: small;">                        <img src="../images/arrow.gif" border="0" width="10" height="11" />                        <a href="Consshorttitle.aspx?<%# Eval("consid") %>">                            <%# Eval("consname") %>                        </a>                    </p>                </ItemTemplate>            </asp:TemplateField>        </Columns>    </asp:GridView>    <asp:SqlDataSource ID="sqldatasource1" runat="server" OnSelecting="AccessDataSource1_Selecting"        ConnectionString="Data Source=.SQLEXPRESS;AttachDbFilename=C:InetpubwwwrooteLawApp_DatasampleDB.mdf;Integrated Security=True;User Instance=True"        ProviderName="System.Data.SqlClient" SelectCommand="SELECT * FROM consindex Order by consname">    </asp:SqlDataSource></asp:Content><asp:Content ContentPlaceHolderID="FooterPlaceHolder1" ID="Content2" runat="server"></asp:Content>--------------------------------------------in this file i am passing the value "A" to (top of the page) "Z" etc...  -------------------------------------------2nd Page <%@ Page Language="C#" AutoEventWireup="true" CodeFile="consA-Z.aspx.cs" Inherits="Cons_consA_Z"    MasterPageFile="~/MasterPage.master" %><asp:Content ID="Content1" ContentPlaceHolderID="ContentPlaceHolder1" runat="server">    <asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="False" CellPadding="3"        DataKeyNames="consid" DataSourceID="AccessDataSource1" Width="100%" AllowSorting="true">        <Columns>            <asp:BoundField HeaderText="consid" Visible="False" />            <asp:TemplateField SortExpression="consid">                <ItemTemplate>                    <table width="80%" align="center">                        <tr>                            <td align="left" width="3%" colspan="3">                                                            </td>                            <td align="left" width="75%">                                                                    <%# Eval("consname")%>                                                            </td>                        </tr>                    </table>                </ItemTemplate>            </asp:TemplateField>        </Columns>    </asp:GridView>    <asp:SqlDataSource ID="AccessDataSource1" runat="server" OnSelecting="AccessDataSource1_Selecting"        ConnectionString="Data Source=.SQLEXPRESS;AttachDbFilename=C:InetpubwwwrooteLawApp_DatasampleDB.mdf;Integrated Security=True;User Instance=True"        ProviderName="System.Data.SqlClient" SelectCommand="SELECT * FROM consindex WHERE consname LIKE '@cons%'">        <SelectParameters>        <asp:QueryStringParameter Name="cons" QueryStringField="cons" Type="int32" />        </SelectParameters>                    </asp:SqlDataSource></asp:Content><asp:Content ContentPlaceHolderID="FooterPlaceHolder1" ID="Content2" runat="server"></asp:Content>-----------------------------The content which i bold in the 2nd file .. wanted dynamically......  please give me a solution ... -----------------------------I want to take the letters starting with A, B, C to Z dynamically in the Second Page,.... Thanks in advance      
 

View 6 Replies View Related

Dynamic 'IN' For Query

Nov 9, 2004

I want to create a report which uses a query that has a dynamic "in" list.
something like

select * from employee where employeeID in (@empid)

when I send @empid = 1,2,3 , it shows a compiler error ,
"syntax error converting the nvarchar value '1,2,3' to a column of data type int'.

any workarounds?

View 3 Replies View Related

Regarding Dynamic Query...

May 15, 2005

Hi,
 I have basic design question regarding dynamic query,
When we have to build a dynamic query (which has table name also as an input parameter),
->Is it better to write a stored procedure ..?
or
->directly specify the dynamic query and set the command type as text in .NET code...?
 
I think,since dynamic queries may not have the advantage of precompliation, it may not yield any performance in using SP's in such case..
 
Please through some light on this,
TIA

View 2 Replies View Related

Dynamic SQL Query

Jul 19, 2005

I have an array list of Branch_ID's; i need to select all records from 2  tables that have any of the branch id's in that array associated with them. How would I go about doing this?

View 3 Replies View Related

Dynamic Query Or Non Dynamic Query

Jan 4, 2001

Hi

I have two options two write queries one Static & one Dynamic.
I wanted to know which one will be good.

Example

if @x = 1
Select * From Customers order by CustomerID
Else IF @x = 2
Select * From Customers Order by CustomerName
Else IF @X = 3
Select * From Customers Order by city
else..
...


Against this
Set @Strsql = "Select * From Customers order by " + @Orderby
Exec (@Strsql)

Which will have better performance ?
Is SQL Stores query plans for static queries with all if statements clause
or it remains as good as dynamic ?

Thanks,
Manoj

View 1 Replies View Related

Dynamic Query :: HELP!

Oct 19, 2004

I'm the new guy and I could use a hand. Any insight would be appreciated.

Basically my task is to create a dynamic way to merge columns from multiple rows. Way the table is set up data is imported and one entry may be up to 3 rows one column from each row can be merged to form a long description, I would like to create a view that would allow you to dynamically query this data and have the description be merged in the result set.

row1 x y z
row2 x b z
row3 x m z


results should look like :: x, (y + b + m) , z


Thank you in advance for any help you can provide!

View 6 Replies View Related

Dynamic Query

Jun 20, 2008

Hi
I am new to sql. I have to run a query in a manner that I can see customer name and their photo dynamically? I already have table created where names and customers images are there.Please help.

Thanks
Swati

View 6 Replies View Related







Copyrights 2005-15 www.BigResource.com, All rights reserved