Monday, March 26, 2012

joning result of dynamic queries

i m making the code of search button in aspx page using C#.

i have multiple dynamic queries that take data from multiple tables

but i dnt know how to join the result of these queries.

example:

1) first query using table1

2)second query using table2

3)third query using table3

how to join the result of these queries at asp.net page?

thanx in advance

If the result sets of all the queries are similar (ie. same number of columns of the same data types)

Then just issue one command with all three queries union'd together

Code Snippet

SELECT x,y,z From Table1

UNION ALL

SELECT x, y z From Table2

UNION All

SELECT x, y, z From Table 3

|||

thanx for reply but it is not useful at all

because i m asking how to combine the result of dynamic queries that relate multiple tables and u r sending simple sql query.i willl try to explain my problem in moredetail as follow.

TABLE NAME COLUMNNAMES

1) tbQualification -- ResumeId,Graduation,PostGraduation

2) tbStrength-- Resumeid,Strength

3)tbExperience Resumeid,YearExperience,MonthExperience

there is a button of SEARCH .clicking on this button search is to be made in all columns fields.this is to be done throgh dynamic query or stored procedure.

this cant be done using simple sql query because we are writting code in aspx page.

plizz help me out

all replies are welcome

Thanx.

|||

You can store the result of each query in the temp table then join those temp tables for your final query...

Code Snippet

Create Table #tbQualificationResult (

ResumeId int,

Graduation varchar(20),

PostGraduation varchar(20)

)

Create Table #tbStrength (

Resumeid int,

Strength int

)

Create Table #tbExperience (

Resumeid int,

YearExperience int,

MonthExperience int

)

Insert Into #tbQualificationResult

Exec sp_executesql 'Your Dynamic Search Query'

Insert Into #tbStrength

Exec sp_executesql 'Your Dynamic Search Query'

Insert Into #tbExperience

Exec sp_executesql 'Your Dynamic Search Query'

Select

COALESCE(A.ResumeId, B.ResumeId, C.ResumeId)

,A.Graduation

,A.PostGraduation

,C.Strength

,C.YearExperience

,C.MonthExperience

From

#tbQualificationResult A

Full OUTER JOIN #tbStrength B on A.ResumeId = B.ResumeId

FULL OUTER JOIN #tbExperience C On A.ResumeId = C.ResumeId

|||

One approach to your issue, from my response and Mani's, is to code the combinations on the back-end in SQL Server.

However, this can also be done at the BI or UI tier.

See these articles for creating datasets with multiple tables and establishing datarelations between those tables.

http://msdn2.microsoft.com/en-us/library/ss7fbaez(VS.80).aspx

http://msdn2.microsoft.com/en-us/library/ay82azad(VS.80).aspx

http://msdn2.microsoft.com/en-us/library/d6s958d6(VS.80).aspx

|||

thanx a lot for reply.

plizz tel how i write query where u say"your dynamic query" because i dnt know how to write dynamic query in sql.

i know only in aspx page and it is different to write in sql so pliz tel.

need urgently

thanx

sql

No comments:

Post a Comment