943,706 Members | Top Members by Rank

Ad:
You are currently viewing page 2 of this multi-page discussion thread; Jump to the first page
Dec 8th, 2008
0

Re: sort data in ms access querie

You can even add sort clause if u like to the same

TO SORT BY DATE
Visual Basic 4 / 5 / 6 Syntax (Toggle Plain Text)
  1. SELECT sNAME, sDATE, sTK FROM (SELECT Table1.name AS sNAME, Table1.date1 AS sDATE, Table1.tk AS sTK from Table1 UNION ALL SELECT Table2.add AS sNAME, Table2.date2 AS sDATE, Table2.tk2 AS sTK FROM Table2) ORDER BY sDATE

OR

TO SORT BY NAME AND DATE
Visual Basic 4 / 5 / 6 Syntax (Toggle Plain Text)
  1. SELECT sNAME, sDATE, sTK FROM (SELECT Table1.name AS sNAME, Table1.date1 AS sDATE, Table1.tk AS sTK from Table1 UNION ALL SELECT Table2.add AS sNAME, Table2.date2 AS sDATE, Table2.tk2 AS sTK FROM Table2) ORDER BY sNAME, sDATE
Reputation Points: 26
Solved Threads: 40
Posting Whiz
aktharshaik is offline Offline
316 posts
since Aug 2008
Dec 15th, 2008
0

Re: sort data in ms access querie

sorry dear I faced a few problem
1. here you gather 6 field in the query by 3 field. but i want the query have both 6 field of both table
I write code like you but it show a msg like
"The number of colums in two selected tables or queries of a union
query do not match"
I dont understand what I need to do. please help me.
Reputation Points: 14
Solved Threads: 78
Practically a Posting Shark
abu taher is offline Offline
835 posts
since Jul 2008
Dec 16th, 2008
0

Re: sort data in ms access querie

when you write a union query u should see that both the queries have equal number of columns and that their datatypes are also same. If suppose one query has 6 and other query has 4 columns then query the remaining 2 columns with empty dummy data. for eg:

Visual Basic 4 / 5 / 6 Syntax (Toggle Plain Text)
  1. SELECT sNAME, sDATE, sTK, sFATHER, sAGE, sPlace FROM (SELECT Table1.name AS sNAME, Table1.date1 AS sDATE, Table1.tk AS sTK, Table1.FatherName as sFATHER, Table1.Age as sAGE, Table1.Place as sPLACE from Table1 UNION ALL SELECT Table2.add AS sNAME, Table2.date2 AS sDATE, Table2.tk2 AS sTK, '' as sFATHER, 0 as sAGE, '' as sPLACE FROM Table2) ORDER BY sNAME, sDATE

Here i assume that the Table1 having fields FatherName, Age and Place fields which are not there in Table2. hence i filled them with empty dummy fields only b'cos to match the total number of columns of both queries joined by the union query. This however being the SELECT query and is only a view, no changes are made to your actual database tables.
Reputation Points: 26
Solved Threads: 40
Posting Whiz
aktharshaik is offline Offline
316 posts
since Aug 2008
Dec 18th, 2008
0

Re: sort data in ms access querie

But when I show the query I can'nt understand what are actual
Reputation Points: 14
Solved Threads: 78
Practically a Posting Shark
abu taher is offline Offline
835 posts
since Jul 2008
Dec 19th, 2008
0

Re: sort data in ms access querie

Use some other notation for those dummy fields like in the query which i had suggested in the last post.

Table2.tk2 AS sTK, '***' as sFATHER, -999 as sAGE, '***' as sPLACE
Reputation Points: 26
Solved Threads: 40
Posting Whiz
aktharshaik is offline Offline
316 posts
since Aug 2008
Aug 26th, 2009
0

For sql server what it should be.?

i try to execute your sql statment in sql query analyzer but it giving following error......

my query
SELECT project_code, ref, rdate, princ,
service [select TblRePayment.project_code,TblRePayment.ref,TblRePayment.rdate,TblRePayment.princ,TblRePayment.service FROM TblRePayment UNION ALL SELECT TblRePayment_re.project_code,TblRePayment_re.ref,TblRePayment_re.rdate,TblRePayment_re.princ,TblRePayment_re.service FROM TblRePayment_re]. AS [%$##@_Alias];

error

Server: Msg 103, Level 15, State 7, Line 2
The identifier that starts with 'select TblRePayment.project_code,TblRePayment.ref,TblRePayment.rdate,TblRePayment.princ,TblRePayment.service FROM TblRePayment ' is too long. Maximum length is 128.
Server: Msg 170, Level 15, State 1, Line 2
Line 2: Incorrect syntax near '.'.
Reputation Points: 10
Solved Threads: 0
Newbie Poster
jyonto is offline Offline
2 posts
since Aug 2009
Aug 26th, 2009
0

For sql server what it should be.?

i try to execute your sql statment in sql query analyzer but it giving following error......

my query
SELECT project_code, ref, rdate, princ,
service [select TblRePayment.project_code,TblRePayment.ref,TblRePayment.rdate,TblRePayment.princ,TblRePayment.service FROM TblRePayment UNION ALL SELECT TblRePayment_re.project_code,TblRePayment_re.ref,TblRePayment_re.rdate,TblRePayment_re.princ,TblRePayment_re.service FROM TblRePayment_re]. AS [%$##@_Alias];

error

Server: Msg 103, Level 15, State 7, Line 2
The identifier that starts with 'select TblRePayment.project_code,TblRePayment.ref,TblRePayment.rdate,TblRePayment.princ,TblRePayment.service FROM TblRePayment ' is too long. Maximum length is 128.
Server: Msg 170, Level 15, State 1, Line 2
Line 2: Incorrect syntax near '.'.

plz. help me out

thanks
Reputation Points: 10
Solved Threads: 0
Newbie Poster
jyonto is offline Offline
2 posts
since Aug 2009
Jun 29th, 2010
0
Re: sort data in ms access querie
select TblRePayment.project_code, TblRePayment.ref, TblRePayment.rdate, TblRePayment.princ, TblRePayment.service FROM TblRePayment UNION ALL SELECT TblRePayment_re.project_code, TblRePayment_re.ref, TblRePayment_re.rdate, TblRePayment_re.princ, TblRePayment_re.service FROM TblRePayment_re

try the above query.
Reputation Points: 26
Solved Threads: 40
Posting Whiz
aktharshaik is offline Offline
316 posts
since Aug 2008
Jun 30th, 2010
0
Re: sort data in ms access querie
ak, do you realize that this thread is almost a year old???
Reputation Points: 156
Solved Threads: 296
Posting Virtuoso
vb5prgrmr is offline Offline
1,670 posts
since Mar 2009

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in Visual Basic 4 / 5 / 6 Forum Timeline: Date problems with MS Access
Next Thread in Visual Basic 4 / 5 / 6 Forum Timeline: Refresh a form





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC