Select Distict And Ordering - Having Trouble

Mar 3, 2007

I have a table where one column is named 'Category'.  I'm hoping to use a DataList to display a two column table, where each cell displays a column name and the number of records in that category.  For example:
Marketing (15)                            Finances (10)
Bath & Body (3)                         Real Estate (7) 
Entertainment (6)                       Construction (2)
I tried this:
SELECT     COUNT(DISTINCT Category) AS Number
FROM         Resources
WHERE     (Approved = 1)

I get this error:
Column Resources.Category is invalid in the 'ORDER BY' clause because it is not contained in either an aggregate function or the Group By clause.  When I try o add the GROUP BY I get a count of one for each category which isn't what I want.  What am I doing wrong?
Diane 

View 3 Replies


ADVERTISEMENT

Need Help - I Have Select Distict Problems

Feb 22, 2007

I'm having an issue with the following sql statement: 1 SELECT Property.PropertyID, Property.ListingEndDate, Property.ListingName, Property.StreetAddress, Property.City, Property.SalePrice,
2 Media.ThumbView
3 FROM Property LEFT OUTER JOIN
4 Media ON Property.PropertyID = Media.PropertyID
I'd like to be able to select by the distinct  Media.PropertyID instead of the Property.PropertyID.  

View 4 Replies View Related

Ordering A UNION Select With Subquery

Jun 26, 2006

I have a select such as this:

select COLUMNS from TABLE where WHERE_CLAUSE1
union
select COLUMNS from TABLE where WHERE_CLAUSE2

Now, I want to order the result set by COLUMNS. When I try the following query, the SQL fails.

select * from
(
select COLUMNS from TABLE where WHERE_CLAUSE1

union

select COLUMNS from TABLE where WHERE_CLAUSE2

) as T
order by COLUMNS

Any idea how this can be done?

Thanks

View 4 Replies View Related

SELECT And Then I'm Clueless. Ordering And Sorting Data

Nov 13, 2007



I want to select the below info from a sql 2005 db, to use it in a dynamic datadriven menu. Only problem, I don't know how to formulate my select statement. So here's the data

ID, TEXT HREF DESCR PARENTID





1
hMenu1
link1.htm
desc text
0


2
hMenu2
link2.html
desc text
0


3
sMenuM1
link3.htm
desc text
1


4
sMenuTSMenu3
link4.htm
desc text
3


I want the data structured so that below the row with id 1, would come it's subitems, subitems for the subitems and so on. So the recordset I'd like to return would in this case be:hMenu1
sMenuM1
sMenuTSMenu3
hMenu2
I've indented the data just to make things clearer. And finally, I want the substructure to be infinite at least in theory.I also do not want to use recursive logic to do this, if possible. I can change the structure of my table if neeed.Cheers!/Eskil

View 7 Replies View Related

SQL Query Question Concerning Distict Results

Jul 10, 2007

hi,I have a query in which I am getting identical results, but I can't use the distict keyword because distinct requires you select the column that you are sorting by. If I do this my results are no longer distinct. Does anyone know how to resolve this issue? 

View 3 Replies View Related

Trouble With A Select Statement

Sep 12, 2005

lets say i have a table that looks like thisclient   date   amount   account1         5/2/05   100   123451         5/2/05   110   123452         5/2/05   175   223342         5/2/05   10     22334How do I select all clients that have an 80 percent difference in amount for the same account on the same day.  For example, only client 2 would be selected.        

View 1 Replies View Related

Select Query Union Trouble

Nov 26, 2007

Given the following tables:

[Members]
-memberID (PK)
-memberName

[Questions]
-questionID (PK)
-questionText

[Surveys]
-surveyID (PK)
-surveyName
-surveyDescription
-surveyType (FK)

[SurveyQuestions]
-surveyID (PK/FK)
-questionID (PK/FK)

[SurveyQuestionMemberResponse]
-surveyID (PK/FK)
-memberID (PK/FK)
-questionID (PK/FK)
-yesResponse(bit)
-noResponse(bit)
-undecidedResponse(bit)

How can I write a query to return the results for a given survey for all members (including members who have not given responses) given the surveyID.

In the [SurveyQuestionMemberReponse] table I record survey results for any members who have answered the survey. However, if a member has not responsed to the survey they will not have a record in this table.

I want to return a list of members with their response to each question in the survey. If a member has not given a response I would like to indicate they have not responded to the survey and they should still appear in the list.

When I attempt to write a query to UNION the results of a query aimed at gathering all of the results in the [SurveyQuestionMemberReponse] to all of the people in the [Members] table I recieve an error when I include the questionText field in my result set.

The error indicates:

The text data type cannot be selected as DISTINCT because it is not comparable.

Can someone please point me in the right direction. I suspect I am going about this all wrong.

[NOTE] The 'surveyType' in the [Surveys] table indicates which subset of members a given Survey should be available to. For this example let's just assume that every survey should belong to all members.

Thanks,

Zoop

View 3 Replies View Related

Trouble With An Insert Into/select Statement

Jan 2, 2008



I have several tables in a database which I always want to update with information from one table with new records (containing contact and demographical information). The setup is something like this:

NewRecordsTable: fn, ln, streetadd, city, emailadd, phonenumber, gender, birthdate

ContactTable: ID(primarykey), fn, ln, streetadd, city, state, zip, phonenumber, email

DemographicTable: ID(linked to primary key ID in Contact table), birthdate, gender


I want to update the ContactTable and DemographicTable with information from the NewRecords Table. What I have done so far is set the identity insert for the ContactTable to on, then inserted the fn, ln, streetadd, email, etc. from the NewTable. This works fine.

I then try to insert ID, birthdate and gender into the DemographicTable where NewRecordsTable.fn=ContactTable.fn AND NRT.ln=CT.ln AND NRT.streetadd=CT.streetadd AND NRT.emailadd=CT.emailadd - This mostly works, but the records which have NULL values any of those fields don't get inserted.

What I really want is to insert the records that have matching email addresses OR matching fn, ln, streetadd combos, but I can't figure out how to get that SELECT/WHERE statement to work.

The problem that underlies this is that I want to insert the ID values from the ContactTable into the DemographicTable, but the only way I can see to make them match properly is by matching the email addresses or fn, ln, streetadd combos from the NewRecordsTable to the ContactTable (all of the email addresses in our NewRecordsTable are unique, unless the person doesn't have an email address, in which case we make sure they have a unique fn, ln, streetadd combo)

Any help would be appreciated,
Thank you!!

View 3 Replies View Related

Select Into And Locking System Tables -- Am I In Trouble?

Sep 27, 2000

I am doing a ‘Select into’ to make a table from at another table which has as many as 130 millions rows (its well indexed). The new table will most often have about 1000 rows. (During the running of the app, the app will be making many new tables, since hopefully this will be a ‘popular’ item by the users. After the users ‘use’ them, they are dropped.)

I know that locks are held on various system tables (including sysobjects) during this ‘select into’ process. Are they held for the entire process?

What should I be concerned about doing ‘select into’?

Thanks for any help,

Judith

View 2 Replies View Related

Trouble Converting SELECT To INSERT Statement

Sep 18, 2005

Trying to convert the following SELECT statement into a INSERT statement and having trouble. No doubt this will be a piece of cake to someone. To eventually get this to a trigger stage would be nice, but for the moment I'd settle for just plain SQL. Using MS SQL 2000. The database name is reporting. The table name is CallLog. I'm trying to convert seperate date (RecvdDate) and time (RecvdTime) columns into a single DateTime column. I've scoured a lot of web pages but I'm still lost.

==============

use reporting
go

SELECT RecvdDate + RecvdTime FROM [dbo].[CallLog]

===============

Any help much appreciated.

View 7 Replies View Related

Trouble Calling Function In View && Multi-Table Select...

Aug 13, 2007

How Do I fix View(below) or Multi-Table select(below) to use this Function to return distinct rows via qcParent_ID?

Following Function populates a field (with concat list of related titles) with other required fields:

Create Function [dbo].openItemsIntoList(@Delimeter varchar(15),@qcparent_ID varchar(1000))

Returns Varchar(8000) as

Begin

Declare @Lists as varchar(8000);



Select @Lists = '';

Select @Lists = @Lists + itemTitle + @Delimeter From z_QClocate_openAll_Qualifier

Where @qcParent_ID = qcParent_ID;

Return Substring(@Lists,1,len(@Lists)-len(@Delimeter));

End

works perfect against single table select (returning 54 distinct rows by qcParent_ID):

Select a.qcParent_ID, a.Facility, a.Modality, openItemListToFix

From dbo.a2_qcEntryForm a

JOIN (Select DISTINCT qcParent_ID, dbo.openItemsIntoList(' / AND ',qcParent_ID) as openItemListToFix FROM dbo.a3_qcItems2Fix) i

on a.qcParent_ID = i.qcParent_ID

But data is needed from 3 tables...
- Created a VIEW that returns all (82) rows (negating distinct of the function on qcParent_ID)
- Failed Miserably Integrating Function call into a multi-table select (inexperienced with complex joins)


This VIEW returns ALL (82) rows in table:


CREATE VIEW z_QClocate_openAll AS

SELECT dbo.a1_qcParent.qcStatus, dbo.a1_qcParent.qcAlert, dbo.a3_qcItems2Fix.qcParent_ID, dbo.a3_qcItems2Fix.qcEntryForm_ID,

dbo.a3_qcItems2Fix.itemComplete, dbo.a3_qcItems2Fix.itemTitle, dbo.a2_qcEntryForm.Facility, dbo.a2_qcEntryForm.Modality

FROM dbo.a1_qcParent INNER JOIN

dbo.a2_qcEntryForm ON dbo.a1_qcParent.qcParent_ID = dbo.a2_qcEntryForm.qcParent_ID INNER JOIN

dbo.a3_qcItems2Fix ON dbo.a2_qcEntryForm.qcEntryForm_ID = dbo.a3_qcItems2Fix.qcEntryForm_ID AND

dbo.a1_qcParent.qcParent_ID = dbo.a3_qcItems2Fix.qcParent_ID

WHERE (dbo.a1_qcParent.qcStatus = 'Awaiting Attn') AND (dbo.a3_qcItems2Fix.itemComplete = 0) OR

(dbo.a1_qcParent.qcStatus = 'In Process') OR

(dbo.a1_qcParent.qcStatus = 'Re-Opened')

Calling like this returns ALL 82 rows (negating the functions distinct):

Select a.qcParent_ID, a.qcStatus, a.qcAlert, a.itemComplete, a.Facility, a.Modality, openItemListToFix

From z_QClocate_openAll a

JOIN (Select DISTINCT qcParent_ID, dbo.openItemsIntoList(' / AND ',qcParent_ID) as openItemListToFix FROM dbo.a3_qcItems2Fix) i

on a.qcParent_ID = i.qcParent_ID

AND THEN THERES...
Failing miserably on Integrating the Function call into This SELECT ON MULTI-TABLES:

How to integrate the Function call:
JOIN (Select DISTINCT qcParent_ID, dbo.openItemsIntoList(' / AND ',qcParent_ID) as openItemListToFix FROM dbo.a3_qcItems2Fix) i

on a.qcParent_ID = i.qcParent_ID

into the multi-table Select relationships (while maintaining Where & Order By):

SELECT dbo.a1_qcParent.qcStatus, dbo.a1_qcParent.qcAlert, dbo.a3_qcItems2Fix.qcParent_ID, dbo.a3_qcItems2Fix.qcEntryForm_ID,

dbo.a3_qcItems2Fix.itemComplete, dbo.a3_qcItems2Fix.itemTitle, dbo.a2_qcEntryForm.Facility, dbo.a2_qcEntryForm.Modality

FROM dbo.a1_qcParent INNER JOIN

dbo.a2_qcEntryForm ON dbo.a1_qcParent.qcParent_ID = dbo.a2_qcEntryForm.qcParent_ID INNER JOIN

dbo.a3_qcItems2Fix ON dbo.a2_qcEntryForm.qcEntryForm_ID = dbo.a3_qcItems2Fix.qcEntryForm_ID AND

dbo.a1_qcParent.qcParent_ID = dbo.a3_qcItems2Fix.qcParent_ID

WHERE (dbo.a1_qcParent.qcStatus = 'Awaiting Attn') AND (dbo.a3_qcItems2Fix.itemComplete = 0) OR

(dbo.a1_qcParent.qcStatus = 'In Process') OR

(dbo.a1_qcParent.qcStatus = 'Re-Opened')


View 3 Replies View Related

Ordering

Mar 3, 1999

Hi there!

We are experiencing a problem using order clause in the statement below:

SELECT
person.pkey
, first_name
FROM
person
, private_person
WHERE
fkey_person = person.pkey
AND first_name = 'A'
ORDER BY
first_name
, person.pkey

Where person table contains the following columns:

pkey, name etc

and private_person

pkey, fkey_person (indexed), first_name (indexed)

The output is:

STEP 1
The type of query is SELECT
FROM TABLE
private_person
Nested iteration
Index : i$private_person$first_name
FROM TABLE
person
Nested iteration
Using Clustered Index
pkey first_name
----------- ---------------------
2000512 A
10994 A
2299 A
1097 A
1218 A
5133 A
1329 A
1387 A
1465 A
7532 A
5513 A
1884 A
512 A
591 A

(14 row(s) affected)

STEP 1
The type of query is SETOFF

Why SQL server does not order by pkey? Is there any information about it somewhere? Is it a bug or what?

If we are ordering by fkey_person everything is Ok. Can anybody help?

Thanks a lot!

Kind Regards,
Vladimir

View 4 Replies View Related

Ordering Ids

Jun 18, 2007

I have a table named as C1_Messages with fields Id, Messages, Dates.
My Id filed looks like this:
1000
1001
1008
1009
1084
1093
1098 etc.

But here I need to make these Ids in a order, means it sould be in a consecutive order. Like
1000
1001
1002
1003
1004
1005 etc.

So is there anyway to do this method in SQL?

Regards
Shaji

View 5 Replies View Related

Ordering In The Table

Jun 27, 2006

Hello,
 
I have made sql table called costreallocation consists of two columsn:
RuleID varchar(10)
Type varchar(20)
I run the following three queries:
insert into costreallocation(RuleId,Type)values('aa','a')
insert into costreallocation(RuleId,Type)values('dd','d')
insert into costreallocation(RuleId,Type)values('cc','a')
then when i notice that these three records are not inserted as they are run:
In the table thn there are three records :
aa      a
cc      d
dd      d
but i need to be filled in the table as they run as:
aa      a
dd      d
cc      d
 
your help is highly appreciated
Best regards
 

View 2 Replies View Related

Ordering Dilemma

Jan 26, 2007

I have an int field - that will hold number for an ordering system. It's a databound field to a textbox in a grid, I want the default to be empty, however not all fields are required so i may have 1-6 as bound values, and the rest should fall in line behind them - the only thing i can think of to do is default the values to 9999 so they come after 1,2,3,4,5,6 etc... I don't like seeing 9999 in my bound fields.
thanks for any suggestions you may have.
 Jeff

View 1 Replies View Related

Advanced Ordering

Mar 5, 2001

Hello.
I want to order a resultset from a table by two columns in another table. Here's how it looks:

[Books]
ID
Title


[linkBookAuthor]
BookID (Books.ID)
AuthorID (Authors.ID)

[Authors]
ID
Firstname
Lastname
AuthorOrder

As you can see it's a many to many relationship. Is there a way to order the books by Authors.Lastname (the first if there are several authors) with one query ? If not, what is the fastest way ? I don't need the names in the resultset so I only want to order the books by Authors.Lastname, not include Authors.Lastname.

Thanks for any help.

View 1 Replies View Related

Ordering By @parameter Possible?

Mar 20, 2001

Hiya!
I've got a little stored procedure:
CREATE PROCEDURE rICDCode @param1 char(15) = 'Description'
AS
SELECT DiagCode, ICD9ID, Description
FROM ICDCodes
ORDER BY @param1
and SQL is returning error 1008 - "The SELECT item identified by the ORDER BY number %d contains a variable as part of the expression identifying a column position. Variables are only allowed when ordering by an expression referencing a column name."
I want to be able to use the same stored procedure for several different functions which all need the same rowset sorted differently. Any way to do this?

Thanks,
Sarah

View 2 Replies View Related

Custom Ordering Top 20 ?

Jul 11, 2005

Hi guys.

I want to create a top 20 product list from a few thousand products. I want the rest of the products to be grouped into 'others'...

I also want the products to be ordered by the facts in the cube. Thus the product dimension would dynamically change depending on the Time dimension thats being selected.

is this plausible ?

Thanks
Tom

View 1 Replies View Related

Ordering By One Field Or Another

May 16, 2008

Is it possible without using CASE statements, to order a result set by one field (if the second field return value is null) or another (if the second field return value is not null)

This would be on datetime fields.
Let's say I have 5 records with 2 date fields
sched_dt and arriv_dt.

sched_dt will always have a value, arriv_dt may or may not have a value.

In a single result set I would like to have the records with an arriv_dt sorted by arriv_dt and the ones without an arriv_dt sorted by sched_dt.

*Hope that makes sense*

Thanks

View 1 Replies View Related

Ordering Dates

Apr 7, 2005

I have a table that has 4 dates for each record (birthday, anniversary, policy_start & policy_end). What I want to do is cycle through each record and then do some calculations using the gaps between the dates. So it
might be Calc1 using (birthday->anniversary), Calc2(anniverary->policy_start), Calc3(policy_start->policy_end), etc. BUT the dates might be in different orders (ie the birthday could come first - or the anniverary could, etc).

In VBA in Excel, I can use the SMALL function within my calcs and this returns the minimum date, the next smallest, the next & then the biggest. But how can I do this in SQL. I guess I can push the 4 dates out to a temp table, order it and then suck them back in - but I have no idea how to do this for all the records in my primary table

I've also tried using various WHERE statements (ie do Calc1 using Birthday & Anniversary WHERE Birthday < Anniversary and ........ - but the code gets awfully long.

Is it possible to write my own SMALL function which uses a bubble sort on the 4 dates & then returns the smallest, next smallest, etc

Any thoughts ?

View 2 Replies View Related

Re-ordering Records

Jul 5, 2007

Hi all,

Ive got a table with a field called 'morder' which orders a menu based on the values in this field (1 for position 1, 2 for position 2 etc...) for example

1 - menu item 1
2 - menu item 2
3 - menu item 3
4 - menu item 4

If I want to add a record to this table and put it at number 2 in the list, i need to update the table to then read...

1 - menu item 1
2 - NEW menu item 2
3 - menu item 2
4 - menu item 3
5 - menu item 4

I want to use a mssql or php function to re-order this field... is it possible??

Hope you can help, and hope it makes sense...

Ash

View 2 Replies View Related

Specific Ordering

Jul 12, 2004

Hi, I was wondering, I have several columns of data that are able to be sorted on - the user just clicks on the column name. However, we have 1 column called order status where we don't want the order to be alphabetical (and it is a text field - a couple current possible values are Processing...In Production...Waiting For Approval). This order is not good for logical sorting - we would want to be able to specify what value would get order. Does that make sense? So we would want to be able to say that Processing is first in the display, Waiting For Approval would be next, then In Production would be next, and so on. Is there any possible way of doing this in a SQL query? Or am I going to have to manually modify all the data adding numbers to the beginning of each data so that it will sort on the numbers? Thanks everyone.

View 4 Replies View Related

About Ordering Of Columns

Jan 2, 2007

i add new column using alter command but i always found it in the end of table but
i want to add it in particular position between the columns...........

how to do so .............:)

View 6 Replies View Related

Ordering By Date

Jun 7, 2007

Hi,I'm streaming data monitoring histories of components into a database table with the following three columns: Hour (DateTime), Id (Int64), and Value (Int32). The Value entry is an aggregate of all values sent from component Id during, and 59 minutes and 59 seconds after, the time listed in the Hour column.I had rather not have to sort the queries after pulling them from the database by date. So I tried to index the DB by the Hour column. Any column will inevitably have duplicates, since the uniqueness depends on a combination of Hour and PortId. But Indexing the Hour column doesn't result in INSERTs being in order as I had expected. Instead, every entry is listed in order of insertion.So. . .how can I keep such a table ordered by date on the disk? I'm afraid this will become very inefficient if this isn't nipped in the bud right now.Thanks so much for your help!-Brandon

View 4 Replies View Related

Ordering Days

May 19, 2004

I have a little query that returns me all the days in a month, but the days are not in the order I need. They come out like so..

January 10
January 11
January 12
January 13
January 14
etc
January 19
January 2
January 20
January 21
January 22

here is my sample code

select [month] + ' ' + [day] as [Date] from mytable
where [month] = 'january'
and [year] = '2004'

Thanks, Jeff

View 10 Replies View Related

Ordering By Months

Jun 9, 2004

I am wondering if someone maybe able to help me, I am needing to order my data via months in the calendar sense not alphabetically, below is what I currently have, but it only does it alphabetically.

select to_char(created,'yyyy-Mon'), matdesc, count(*)
from test
group by to_char(created,'yyyy-Mon'), matdesc
order by to_char(created,'yyyy-Mon') desc

any help would be greatly appreciated

Thank you

Stephen

View 11 Replies View Related

Ordering Results

Jul 25, 2007

I am trying to do a simple SQL query..the result will be sorted alphabetically by default, but i need to specify say, if there is a "Others" it will be placed last in the list. Is there any way to write the query using ORDER BY?

e.g
Australia
China
Others
USA

and i want it to be:
Australia
CHina
USA
OThers

View 1 Replies View Related

Ordering Within Hierarchy

Aug 7, 2007

Hi all,

Ive got a bit of a problem,

I have two tables:

CATEGORY
id
name
parent_CATEGORY_id

RECORD
id
CATEGORY_id
Stock_Held_Number

ps. Ive stripped out any non relevant fields


I also have the following query (again ive stripped out the non-relevant fields)

SELECT TOP (100) PERCENT SUM(dbo.RECORD.Stock_Held_Number) AS TotalStock, CATEGORY.Name AS FundName
FROM CATEGORY
LEFT OUTER JOIN dbo.RECORD ON CATEGORY.ID = dbo.RECORD.CATEGORY_id
GROUP BY CATEGORY.Name, RECORD.Stock_Held_Number

At the moment its grouping all the CATEGORIES and giving me a sum total for each which is great.

The problem I have is the CATEGORY table, there is an optional join to parent CATEGORY records on the table.

What Im trying to do is to provide a fully ordered result within the CATEGORIES and I don't have a clue.

For example:

The CATEGORY table has the following values
ID Name Parent_Category_id
1 Pens
2 Animals
3 Rocks
4 Horses 2
5 Dogs 2

When I currently run the query I get:
Name TotalStock
Pens 20
Animals 30
Rocks 40
Horses 50
Dogs 60

It's technically correct because I don't want the parent to calculate the total value of the children

What Im really trying to do is order them within the hierarchy though and indent (if possible) the result so I would get

Name TotalStock
Animals 30
---Dogs 60
---Horses 50
Pens 20
Rocks 40

Does anybody have any pointers as to how I can achieve this.

Many thanks

Mike

View 3 Replies View Related

Ordering Rows

Feb 18, 2008

hi,

i have following data:

create table tb_customer (customer_id int, order_id varchar (12))
insert into tb_customer (customer_id, order_id) values (123, 2201)
insert into tb_customer (customer_id, order_id) values (123, 2246)
insert into tb_customer (customer_id, order_id) values (123, 2236)
insert into tb_customer (customer_id, order_id) values (123, 1253)
insert into tb_customer (customer_id, order_id) values (120, 1201)
insert into tb_customer (customer_id, order_id) values (127, 2251)
insert into tb_customer (customer_id, order_id) values (127, 2231)
insert into tb_customer (customer_id, order_id) values (122, 2121)

and i want to get the following output:

output:
Nu_order | customer_id| order_id
1 |123| 2201
2 |123| 2246
3 |123| 2236
4 |123| 1253
1 |120| 1201
1 |127| 2251
2 |127| 2231
1 |122| 2121

any idea?

thank you

View 11 Replies View Related

Ordering, Grouping - HELP!

Jul 23, 2005

Having recently had excellent service here (many thanks, Erland!),here's another wee problem.SQL 2000I need to get a report which will display the movement of people thus:ID DIRECTION NAME DATE VEHICLE REGISTRATIONThe value of DIRECTION can be either "Inbound" or "Outbound"I need to have the data grouped by ID, with the "Outbound" row first.For example1 "Outbound" Smith 10/02/2005 ABC1231 "Inbound" Smith 11/02/2005 ABC1235 "Outbound" Jones 14/02/2005 XYZ7895 "Inbound" Jones 15/02/2005 DEF456This is the SQL so far.SELECTfldPersonID,tblMovementType.fldType AS [MovementType],'Outbound' AS [Direction],fldMovementDate AS [Date],CASE WHEN tblPerson.fldForenames IS NULLTHEN fldSurnameELSE fldSurname + ', ' + fldForenames END AS [Name],'Outbound ' + fldVehicleOut AS VehicleRegistrationFROMtblPersonINNER JOIN tblMovementTypeON tblMovementType.fldMovementTypeID = tblPerson.fldMovementTypeWHERE((fldMovementDate BETWEEN @FromDate AND @ToDate) AND(fldStatus = 1))UNION ALLSELECTfldPersonID,tblMovementType.fldType AS [MovementType],'Inbound' AS [Direction],fldMovementDate AS [Date],CASE WHEN tblPerson.fldForenames IS NULLTHEN fldSurnameELSE fldSurname + ', ' + fldForenames END AS [Name],'Inbound '+ fldVehicleRtn AS VehicleRegistrationFROMtblPersonINNER JOIN tblMovementTypeON tblMovementType.fldMovementTypeID = tblPerson.fldMovementTypeWHERE((fldMovementDate BETWEEN @FromDate AND @ToDate) AND(fldStatus = 1))What I need is the way to Order or Group it so that I can just put therows into a report without any grouping on the report itself (CrystalReports aarrggh!) - if this is possible!Edward--The reading group's reading group:http://www.bookgroup.org.ukThanks

View 1 Replies View Related

Ordering Problem

Jul 23, 2005

Hi everyone, I have a database (not designed by me) in sql server, I amhaving trouble ordering it correctly, and I would appreciate any help.Here is my structure, it's sort of hierarchical:TABLE_AID_COLSUB_ID_COLTABLE_BID_COL'NAMEThis could be thought of as an employee and supervisor structure. Wehave employees (TABLE_B) and their relationship (TABLE_A).I know I need to use a group and oder by, but I am drawing blankstoday. I need the result to be (if using the employee example):Bob-Ryan-SueMarkNick-George-Paul--Ringo--StarHere is my half-hearted stab at it:SELECT *FROM TABLE_A AINNER JOIN TABLE_B BGROUP BY A.SUB_ID_COLORDER BY NAME;Thank you very much for any help you can offer.Have a great night!Ryan

View 4 Replies View Related

Ordering An Int Column

Sep 26, 2005

I've created a clustered two column index on a table where the secondcolumn is an integer value. When the first column is the same, insteadof ordering in numerical order it is ordering 1,10,100,2,20,200 etc.How can I change the behaviour to order the data in numerical order?Thanks,Rick

View 9 Replies View Related

ORDERING OF DATA

Jul 20, 2005

HOW TO ORDER THIS DATA.MONTH-YEAR10-200310-202011-20033 -20034 -20035 -20036 -20037 -20038 -20039 -2003THANX IN ADV.Join Bytes!

View 2 Replies View Related







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