Order Results By Date Not Working

Oct 3, 2006

hi. i'm trying to order my results ascending by date except i'm getting some really weird output. my ouput resembles something like this:

oct 2
oct 3
sep 13
sep 21
sep 22
sep 30
aug 3
aug 5
aug 16

the data is stored in a date field. i use getdate when inserting the date to the database. is there a reason why the dates are showing up weird and not ordering appropriately? thanks for your help.

also, can you not search here any more? i keep getting timeout errors.

View 7 Replies


ADVERTISEMENT

ORDER BY [Date] Isn't Working Since It's Not A DateTime (it's A Varchar!)

Mar 4, 2004

Hi everyone.

I know, I know, it should have been a datetime from the start...but here's the problem.

I'm trying to sort by my date field but because it looks like: "04/03/2004 12:14:21 PM" it's not ordering it properly using:

ORDER BY [Date]

Are there any work arounds for this? Is there some way of doing:

ORDER BY covert(datetime, [Date], 103) or something?

Cheers
Andrew

View 3 Replies View Related

SQL To Order Results In Predefined Order

Mar 27, 2008

I have a DB with items which can have lengths from 0 to 400 meter.In my resultset I want to show the items with length 1-400 meter and then the results with length 0 meterHow to build my SQL?

View 4 Replies View Related

Specify Order For Select Results, Order By: Help!

Nov 17, 2006

Lets say I have a table named [Leadership] and I want to select the field 'leadershipName' from the [Leadership] Table.

My query would look something like this:

Select leadershipName
From Leadership

Now, I would like to order the results of this query... but I don't want to simply order them by ASC or DESC. Instead, I need to order them as follows:

Executive Board Members, Delegates, Grievance Chairs, and Negotiators

My question: Can this be done through MS SQL or do I need to add a field to my [Leadership] table named 'leadershipImportance' or something as an integer to denote the level of importance of the position so that I can order on that value ASC or DESC?

Thanks,

Zoop

View 1 Replies View Related

Find Order By Date Range Or Order Id

May 8, 2007

hi basically what i have is 3 text boxes. one for start date, one for end date and one for order id, i also have this bit of SQL
SelectCommand="SELECT [Order_ID], [Customer_Id], [Date_ordered], [status] FROM [tbl_order]WHERE (([Date_ordered] >= @Date_ordered OR @Date_ordered IS NULL) AND ([Date_ordered] <= @Date_ordered2 OR @Date_ordered2 IS NULL OR (Order_ID=ISNULL(@OrderID_ID,Order_ID) OR @Order_ID IS NULL))">
 but the problem is it does not seem to work! i am not an SQL guru but i cant figure it out, someone help me please!
Thanks
Jez

View 4 Replies View Related

ORDER BY Not Working!

Apr 23, 2008

I'm trying to create a view using the following code:

quote:SELECT TOP (100) PERCENT Program, COUNT(Program) AS Total,
(SELECT COUNT(Program) AS Count
FROM dbo.Active_Enrollments_by_Earn
WHERE (CDE_PROJ LIKE 'NC%') AND (Program = List.Program)
GROUP BY Program) AS CDC,
(SELECT COUNT(Program) AS Count
FROM dbo.Active_Enrollments_by_Earn AS Active_Enrollments_by_Earn_1
WHERE (CDE_PROJ LIKE 'WS%0') AND (Program = List.Program)
GROUP BY Program) AS WSC
FROM dbo.Active_Enrollments_by_Earn AS List
GROUP BY Program
ORDER BY Program
On my server, it sorts the resulting view in alphabetical order automatically (it didn't matter if I put "ORDER BY Program"). On my production server, however, it doesn't sort by Program at all and I can't seem to resolve it. HELP!

View 11 Replies View Related

ORDER BY Not Working With ADO Or OLE

Aug 29, 2007

I am inserting rows into an Excel file and the ORDER BY is coming out wrong.

When I run the select I get priority 1,2,3,4, ...10, 11, 12, ... as I should.
But in the excel file the rows come out 1,10,11,12,13 ..., 2, 20, 21, ...


SET @sql = ' INSERT INTO OpenRowset(''Microsoft.Jet.OLEDB.4.0'',''Excel 5.0;Database='+@finalFile+';HDR=YES'',

''SELECT [ID],[Priority],[Comments] FROM [Sheet1$]'')

SELECT ID,priority,comments FROM OurTable WHERE orgId='+@orgId+' ORDER BY priority,ID'


EXECUTE (@sql)

Please help!! Thank you!

View 1 Replies View Related

Results In Order

Jun 13, 2007

I have the following query and I am wanting to get the results to be in order. Right now, it shows me the results by date, but the dates are out of order. How can I get it to give me the results by date in date order???

SELECT DISTINCT MDN, dateadd(day, datediff(day, 0, CallDate), 0) as CallDate,sum(PaidBalCost), sum(BonusBalCost), sum(ceiling((Cast(DurationSeconds as Decimal)/60))) as Minutes
FROM VoiceCallDetailRecord
WHERE CallDate >= '02/19/2007' and calldate < '03/19/2007'
and NOT (Left(Endpoint,3) IN ('011')
or (Left(Endpoint,4) IN ('1340','1876','1868','1809',
'1246','1242','1780','1403',
'1250','1604','1807','1519',
'1204','1506','1709','1867',
'1902','1705','1613','1416',
'1905','1902','1514','1450',
'1418','1819','1306','1867')))
AND (((CONVERT(varchar, CallDate, 108) Between '07:00:00' AND '20:59:59'))
AND DATEPART(weekday, CallDate) in (2,3,4,5,6))
Group By MDN, dateadd(day, datediff(day, 0, CallDate), 0)
UNION
SELECT DISTINCT MDN, dateadd(day, datediff(day, 0, CallDate), 0) as CallDate,sum(PaidBalCost), sum(BonusBalCost), sum(ceiling((Cast(DurationSeconds as Decimal)/60))) as Minutes
FROM ZeroChargeVCDRecord
WHERE CallDate >= '02/19/2007' and calldate < '03/19/2007'
and NOT (Left(Endpoint,3) IN ('011')
or (Left(Endpoint,4) IN ('1340','1876','1868','1809',
'1246','1242','1780','1403',
'1250','1604','1807','1519',
'1204','1506','1709','1867',
'1902','1705','1613','1416',
'1905','1902','1514','1450',
'1418','1819','1306','1867')))
AND (((CONVERT(varchar, CallDate, 108) Between '07:00:00' AND '20:59:59'))
AND DATEPART(weekday, CallDate) in (2,3,4,5,6))
Group By MDN, dateadd(day, datediff(day, 0, CallDate), 0)

View 5 Replies View Related

Order By Not Working Properly

Jan 17, 2007

Hello, i have something like this, i want the annoucements (status = 0) to be on top, then topics with (status = 1) below, then the rest of the topics.
So i tried:
SELECT forum_topics.id, forum_topics.status, forum_topics.username AS starter, forum_topics.subject, forum_topics.closed, forum_topics.answerpostid, forum_topics.views, forum_topics.answers, forum_topics.lastanswer, forum_topics.lastanswerid, forum_topics.created AS started, forum_answer.username, forum_answer.answer, forum_answer.created FROM forum_topics LEFT OUTER JOIN forum_answer ON forum_answer.id = forum_topics.lastanswerid WHERE (boardid = @ID OR boardid = 0) ORDER BY (status) ASC, (created) ASC
Problem is that they are not sorted diffrently, when i change the (created) ASC to (created) DESC i get the same result and the rows are not sorted, they only get sorted by status so i have status=0 at the top, then status=1 then the rest. How do i get them to be sorted first by status ASC then by created ASC/DESC?
Patrick

View 1 Replies View Related

ORDER BY Not Working With Subquery Value

Dec 11, 2007

So.. I'm trying to add up the number of wins and losses from a schedule of games and list them with their corresponding team name from another table.

Then I want to be able to sort by each teams number of wins. This is what I've got now, and it runs through without error, but it does not ORDER the list by "Wins"


strSQL = "Select *, ((SELECT Count(Win) FROM Game_Schedule WHERE Game_Schedule.T1_ID = standings.ID AND Win = true) + " & _
"(SELECT Count(Win) FROM Game_Schedule WHERE Game_Schedule.T2_ID = standings.ID AND Loss = true)) AS [Wins], " & _
"(SELECT Count(Loss) FROM Game_Schedule WHERE Game_Schedule.T1_ID = standings.ID AND Loss = true) + " & _
"(SELECT Count(Loss) FROM Game_Schedule WHERE Game_Schedule.T2_ID = standings.ID AND Win = true) AS [Losses], " & _
"(SELECT Count(Tie) FROM Game_Schedule WHERE Game_Schedule.T1_ID = standings.ID AND Tie = true OR Game_Schedule.T2_ID = standings.ID AND Tie = true) AS [Ties] FROM standings ORDER BY T_Tier, T_Name, Wins DESC"

View 2 Replies View Related

ORDER BY In VIEW Not Working

Jan 24, 2006

I have the view below and if I use vwRouteReference as the rowsourcefor a combo box in an MS Access form or run "SELECT * FROMvwRouteReference" in SQL Query Analyzer, the rows don't come throughsorted by Numb.Everything I've read on the web suggests that including the TOPdirective should enable ORDERY BY in views. Does someone have an ideawhy the sorting is not working correctly for this particular view? thanks.CREATE VIEW vwRouteReferenceASSELECT TOP 100 PERCENT tblItem.ID,tblItem.Numb + ' - ' + tblQuestion.DescrPrimary AS FullName,tblItem.Numb, tblQuestion.DescrPrimary AS TypeFROM tblItem INNER JOIN tblQuestionON (tblItem.ID = tblQuestion.Item_ID)WHERE (((tblItem.Category_ID)>0))UNIONSELECT TOP 100 PERCENT tblItem.ID,tblItem.Numb + ' - ' + tblItem.Type + ' : ' + tblItem.Class AS FullName,tblItem.Numb, tblItem.Type + ' : ' + tblItem.Class AS TypeFROM tblItemWHERE (((tblItem.Type) = 'Assignment' OR (tblItem.Type) = 'Check' OR(tblItem.Type) = 'Route'))ORDER BY tblItem.Numb

View 49 Replies View Related

View 'order By' Not Working

Sep 22, 2006

Hi there,

I have a view created using the following code. The view works perfectly but does not order by the name column as I've asked it to do. In the view designer if I click on execute then the order is applied but if I save the view and run it externally (i.e. in an ASP page or within the management terminal) it does not order correctly and seems to order by the Id column.

Any help would be much appreciated. Here's the code:

SELECT TOP (100) PERCENT dbo.Members.DivisionID, COUNT(*) AS Members, dbo.Country.Name
FROM dbo.Members INNER JOIN
dbo.Country ON dbo.Members.DivisionID = dbo.Country.CountryID AND dbo.Members.CountryID = dbo.Country.CountryID
GROUP BY dbo.Members.DivisionID, dbo.Country.Name
ORDER BY dbo.Country.Name

And another, more simpler view, that doesn't sort as it's supposed to.

SELECT TOP (100) PERCENT CountryID, Name, RegionID, IsActive, HasFlag, URL, Comments
FROM dbo.Country
ORDER BY Name

Many thanks,

Ady

View 5 Replies View Related

Working With Results

Mar 5, 2007



I tried all of the other forums with no luck.

Using visual basic, c#, or c++ Forms and applications

Here is what I want to do:

I place a datagridview obj on the form and it works no problems. How do you take one of the columns and add all of the data (numeric) from all of the rows to show a total of all of the numbers in a text field obj added to the bottom of the form.



For example, I want to use it for office expenses and I have one table field named "cost" and at the bottom I want to show total cost (all rows added together).



Thanks in advance

View 3 Replies View Related

How To Order Results From DateName?

Mar 13, 2008

HiI want to get the dateName of everything but I don't know how to sort them now. Like I have this:DateName(month,TimeDateStamp) As TimeDateStampWhat gets the dateName now I want to sort these so that they are in order.How do I do this?  

View 3 Replies View Related

Order / Rank Results

Feb 8, 2006

Hi,

i want to create a report so that a list of the top 30 records are returned to the report user. In the report i want to have the records position in the list shown (ie the first row should have 1. and the second should be 2. right on down to the 30th having 30.)

how do i achieve this please?


many thanks
FatherJack

View 1 Replies View Related

Top + Order By = Strange Results

Mar 14, 2008

Hi there,I'm a little bit confused here. I the TOP 1 function with ORDER BY DESC to get the last id in my table but it doesn't seems to work.Here's an example:SELECT TOP 1 ID FROM Worksheet WHERE Style='302' AND Notes='Automatically created from m0851System.' AND Title='STD COST UPDATED FORM m0851System' ORDER BY ID DESCSELECT ID FROM Worksheet WHERE Style='302' AND Notes='Automatically created from m0851System.' AND Title='STD COST UPDATED FORM m0851System' ORDER BY ID ASCSo basically the first SELECT should return the last id value of the second query but it doesn't.The first query gives me that: 60721And the second one gives me that:60680606816068360684606856068660718607196072060721610506112261124So as you can see my TOP 1 ID ORDER BY ID DESC should gave me this result: 61124Am I missing something or... ?Please help me this is aleready in function so I have to fix it ASAP.Thank you, Regards,OR-THO

View 5 Replies View Related

Select Like And Order Results

Apr 25, 2008

Hello there,

I have two tables I selecting name using like with %string% from the two tables but I need to order the result comes from the two table:
1- the exact match for the search string come first from the two table.
2- and the partial match comes last after the exact match.

this is my DDL for the two tables :


USE [Northwind]
GO
/****** Object: Table [dbo].[Person] Script Date: 04/25/2008 14:33:24 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
SET ANSI_PADDING ON
GO
CREATE TABLE [dbo].[Person](
[PersonID] [int] NULL,
[Type] [char](10) COLLATE SQL_Latin1_General_CP1_CI_AS NOT NULL,
[Name] [varchar](50) COLLATE SQL_Latin1_General_CP1_CI_AS NOT NULL,
[email] [varchar](50) COLLATE SQL_Latin1_General_CP1_CI_AS NOT NULL
) ON [PRIMARY]

GO
SET ANSI_PADDING OFF


second table:
USE [Northwind]
GO
/****** Object: Table [dbo].[Members] Script Date: 04/25/2008 14:33:52 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
SET ANSI_PADDING ON
GO
CREATE TABLE [dbo].[Members](
[MemberID] [int] NULL,
[Type] [char](10) COLLATE SQL_Latin1_General_CP1_CI_AS NOT NULL,
[Name] [varchar](50) COLLATE SQL_Latin1_General_CP1_CI_AS NOT NULL,
[Email] [varchar](50) COLLATE SQL_Latin1_General_CP1_CI_AS NOT NULL
) ON [PRIMARY]
GO
SET ANSI_PADDING OFF


and this my search query I have it in a stored Proc.


select *

from

(





SELECT PersonID, Type, Name, email


FROM Person
WHERE (Name LIKE '%'@Name'%')
union all

SELECT PersonID, Type, Name, email


From Members
WHERE (Name Like '%'@Name'%' )

) Y



Order by

Case[Name] when @Name Then 1 Else 2 End,

Case[Name] when 'm' Then 1 Else 2 End

Thank you for your time
Sms

View 5 Replies View Related

Transact SQL :: Return Date Which Is 15 Working Days Prior To Given Future Date

Oct 28, 2015

i have written a sql function which returns only number of working days (excludes holidays and Weekends)  between given StartDate  and EndDate.
                 
USE [XXX]
GO
/****** Object:  UserDefinedFunction [dbo].[CalculateNumberOFWorkDays]    Script Date: 10/28/2015 10:20:25 AM ******/
SET ANSI_NULLS ON
GO

[code]...

I need  a function or stored procedure which will return the date which is 15 working days (should exclude holidays and Weekends) prior to the given future Date? the future date should be passed as a parameter to this function or stored procedure to return the date.  Example scenario:  If i give date as  12/01/2015, my function or stored procedure should return the date which is 15 working days (should exclude holidays and Weekends) prior to the given date i.e 12/01/2015...In my application i have a table  tblMasHolidayList where all the 2015 year holidays dates and info are stored.

View 18 Replies View Related

Sql SORT Order Not Working On Numbers?

Jul 20, 2005

Hello all... I'm using asp to get records from an access database, verysimilar to the way datagrid would work. The title of each column in my tableis a link that alternates the sort order between ascending and descending...my problem is that text WILL change its sort order just fine but nubers arenot always in order. ie: if sort order is ASC (ascending) I might see 2000,234, 789 (should be ordered but its not). I'm guessing that ASP is handingthe string as a text string (?) and getting confused, is there a way toforce ASP into treating the string as numerals if this is the case? anyother ideas? Thanks so much.here is one of my sql commands in case you want to see it. "sort" is avariable containing the recordset to sort by depending on which link isclicked. I hope I didn't confuse the whole issue because of a lack ofcaffiene over here :)strsql = "SELECT * FROM comments ORDER BY " & sort & " DESC"Thanks of the help, much appreciated.Eno

View 2 Replies View Related

Sql Error-order By Clause Not Working

Aug 27, 2007

Hi,


I have the following code and output


select distinct week ,sum(itemvalue) as itemvalue from (Select ATP,

WEEK=

CASE

WHEN (datepart(Dd, ATP) < 7 AND datename(Month,ATP)='JANUARY')

OR

( datepart(Dd, ATP) < 8 AND datename(Month,ATP)='JULY')

OR

( datepart(Dd, ATP) < 7 AND datename(Month,ATP)='OCTOBER')

THEN '1'

WHEN (datepart(Dd, ATP) < 14 AND datename(Month,ATP)='JANUARY')

OR

( datepart(Dd, ATP) < 15 AND datename(Month,ATP)='JULY')

OR

( datepart(Dd, ATP) < 14 AND datename(Month,ATP)='OCTOBER')

THEN '2'

WHEN (datepart(Dd, ATP) < 21 AND datename(Month,ATP)='JANUARY')

OR

( datepart(Dd, ATP) < 22 AND datename(Month,ATP)='JULY')

OR

( datepart(Dd, ATP) < 21 AND datename(Month,ATP)='OCTOBER')

THEN '3'

WHEN (datepart(Dd, ATP) < 28 AND datename(Month,ATP)='JANUARY')

OR

( datepart(Dd, ATP) < 29 AND datename(Month,ATP)='JULY')

OR

( datepart(Dd, ATP) < 28 AND datename(Month,ATP)='OCTOBER')

THEN '4'

WHEN ((datepart(Dd, ATP) IN (29,30,31)) AND datename(Month,ATP)='JANUARY')

OR

( (datepart(Dd, ATP) IN (29,30,31)) AND datename(Month,ATP)='JULY')

OR

( (datepart(Dd, ATP) IN (28,29,30,31)) AND datename(Month,ATP)='OCTOBER')

THEN '5'

WHEN (datepart(Dd, ATP) < 4 AND datename(Month,ATP)='FEBRUARY')

( datepart(Dd, ATP) < 5 AND datename(Month,ATP)='AUGUST')

OR

( datepart(Dd, ATP) < 4 AND datename(Month,ATP)='NOVEMBER')

THEN '5'

WHEN (datepart(Dd, ATP) <11 AND datename(Month,ATP)='FEBRUARY')

OR

( datepart(Dd, ATP) < 13 AND datename(Month,ATP)='MAY')

OR

( datepart(Dd, ATP) < 12 AND datename(Month,ATP)='AUGUST')

OR

( datepart(Dd, ATP) < 11 AND datename(Month,ATP)='NOVEMBER')

THEN '6'

WHEN (datepart(Dd, ATP) < 18 AND datename(Month,ATP)='FEBRUARY')

OR

( datepart(Dd, ATP) < 19 AND datename(Month,ATP)='AUGUST')

OR

( datepart(Dd, ATP) < 18 AND datename(Month,ATP)='NOVEMBER')

THEN '7'

WHEN (datepart(Dd, ATP) < 25 AND datename(Month,ATP)='FEBRUARY')

OR

( datepart(Dd, ATP) < 27 AND datename(Month,ATP)='MAY')

OR

( datepart(Dd, ATP) < 31 AND datename(Month,ATP)='AUGUST')

OR

( datepart(Dd, ATP) < 25 AND datename(Month,ATP)='NOVEMBER')

THEN '8'

WHEN ((datepart(Dd, ATP) IN (25,26,27,28)) AND datename(Month,ATP)='FEBRUARY')

OR

( (datepart(Dd, ATP) IN (27,28,29,30,31)) AND datename(Month,ATP)='MAY')

OR

( (datepart(Dd, ATP) IN (25,26,27,28,29,30)) AND datename(Month,ATP)='NOVEMBER')

OR

( (datepart(Dd, ATP) <2) AND datename(Month,ATP)='DECEMBER')

THEN '9'

WHEN (datepart(Dd, ATP) < 11 AND datename(Month,ATP)='MARCH')

OR

( datepart(Dd, ATP) < 9 AND datename(Month,ATP)='SEPTEMBER')

OR

( datepart(Dd, ATP) < 9 AND datename(Month,ATP)='DECEMBER')

THEN '10'

WHEN (datepart(Dd, ATP) < 18 AND datename(Month,ATP)='MARCH')

OR

( datepart(Dd, ATP) < 16 AND datename(Month,ATP)='SEPTEMBER')

OR

( datepart(Dd, ATP) < 16 AND datename(Month,ATP)='DECEMBER')

THEN '11'

WHEN (datepart(Dd, ATP) < 25 AND datename(Month,ATP)='MARCH')

OR

( datepart(Dd, ATP) < 23 AND datename(Month,ATP)='SEPTEMBER')

OR

( datepart(Dd, ATP) < 23 AND datename(Month,ATP)='DECEMBER')

THEN '12'

WHEN (datepart(Dd, ATP) > 24 AND datename(Month,ATP)='MARCH')

OR

( datepart(Dd, ATP) > 22 AND datename(Month,ATP)='SEPTEMBER')

OR

( datepart(Dd, ATP) < 30 AND datename(Month,ATP)='DECEMBER')

THEN '13'

ELSE 'BEYOND'

END , SUM(ITEMVALUE) as ITEMVALUE



FROM tOPENLINE_MODIFIED

LEFT OUTER JOIN

tZCHANNEL ON tOPENLINE_MODIFIED.ZCHANNEL = tZCHANNEL.ZCHANNEL

WHERE RequestQtr in ('Q4')

and tOPENLINE_MODIFIED.ATP >= '7/01/07'

and tOPENLINE_MODIFIED.ORDERTYPE in ('OR','ZBOS','ZECM','ZOR','ZOB','ZEXP')

and dbo.tZCHANNEL.ZCHANNEL in ('D','I','01', '02', '06', '07', '10')

and tOPENLINE_MODIFIED.ACCTASSIGNGRP in ('01','02')

AND tOPENLINE_MODIFIED.SOLD2NAME NOT LIKE ('%celestica%')

AND tOPENLINE_MODIFIED.SOLD2NAME NOT LIKE ('%giant%')

and tOPENLINE_MODIFIED.PLANT IN ('COF1', 'I405', 'I375', 'IOM4', 'IOM5', 'I316')

GROUP BY ATP)as A

GROUP BY week

output:

week itemvalue

------ ---------------------

1 1214003.60

10 9257193.45

11 12095432.11

12 11429629.08

13 7315751.08

2 1052337.53

3 951038.10

4 274769.21

5 465278.37

6 78003.67

7 607681.02

8 9042948.17

9 2255545.25

but i need the output as

week
1
2
3
4
5
6
7
8
9
10
11
12
13

iam not able to achieve this after trying so many times.Please help me on this.

Thanks,
SVGP
















View 6 Replies View Related

SQL Search Results Not Working???

Dec 10, 2005

Can anyone suggest whey I dont get any results with this search?

SQL reads:

SELECT SupplierName, Location, ShortDescription
FROM Query1
WHERE 'TimberSpecies' LIKE '%MMColParam%' AND 'CategoryTable' LIKE '%MMColParam2%' AND 'Location' LIKE '%MMColParam3%'

MMColParam 1 Request.Form("keywordSearch")
MMColParam2 2 Request.Form("location")
MMColParam3 3 Request.Form("category")

Mally.

View 4 Replies View Related

How To Order Search Results By Relevance?

Jul 3, 2007

I need to order my search results by relevance to the keywords entered by the user, how can i do that in sql ?

View 6 Replies View Related

Concatenate Results In Specific Order

Jul 24, 2013

I am trying to Concatenate resulting classification names (X_DSC_CD_ABR below) in the following order (if the classification exists), separated by '/': WC/STD/LTD/FMLA/State/Military/Paid/Corporate/PFL/Other

Examples:
a. STD/FMLA
b. STD/LTD/FMLA/Other

View 2 Replies View Related

Ordering Results By Order Of The IN' Clause

Jul 28, 2006

Consider this SQL:SELECT my_field FROM my_table WHERE my_field IN ('value2', 'value1','value3')Simple enough, but is there anyway to specify that the result should beordered exactly like the "IN" clause states? So when this recordsetcomes back, I want it like this:my_field------------value2value1value3Possible?Deane

View 5 Replies View Related

Updating Database Date Field Results In Date Value Of 01/01/1900

Jun 18, 2007

Brand new to this, so please bear with me.I'm using the following code fragment to update a datetime field on a SQL Server 2005 database table:cmd.CommandText = "Update Projects Set EntryDate = " & Convert.ToDateTime(txtEntryDate.Text)cmd.ExecuteNonQuery()The result of the update operation is the the database field contains the value "1900-01-01 00:00:00:000".  This probably means that I passed nulls to SQL; however, I see a valid date in the txtEntryDate field on my web form (i.e., "06/18/2007").  I also did a "Response.write" to display the txtEntryDate and it looks Okay.Can someone tell me what I'm doing wrong?Thanks!Using Visual Web Developer 2005 Express.

View 1 Replies View Related

Excel Data Mining Add In: Order By Not Working

Apr 24, 2007

Hello,



I am trying insert the "Order by" clause into DMX but nothing is working.



INSERT INTO MINING STRUCTURE [ARS] (
[OrderID],
[Product_Table](SKIP, [Product])
)
SHAPE {
OPENQUERY ([dwMDA on PSD_TEST_TEST], 'Select Top 30000 "OrderID"
From "dwMDA"."dbo"."vDetail" Order By "OrderID"')
} APPEND
( {
OPENQUERY ([dwMDA on PSD_TEST_TEST], 'Select Top 30000 "OrderID","Product"
From "dwMDA"."dbo"."vDetail" Order By "OrderID"')} RELATE [OrderID] TO [OrderID]
) AS T



This is the DMX for market basket analysis.



I am also unable to use "order by" when i pull data into excel.



here's an example of something that doesn't work:



Select Top 20000 "OrderID","ProductGroupDescription"
From "dwMDA"."dbo"."vDetail"

Order By "OrderID"



Can someone show me the exact working SQL commands they are using for the "Order By" clause when they import data from sql into an excel spreadsheet?



Even better would be if someone

1. Open excel, and go to the data mining tab

2. Click on the Cluster Button

3. Select Analysis Service Data Source

4. Input a command the includes "Order By"

5. Run the model

6. Show me the tracer.



Thanks



Davy

View 1 Replies View Related

Working With Results From A Stored Procedudure

Nov 2, 2007

I am working with a complex Stored Procedure which I need to be able to filter and sort by various criteria. Can I please ask how I can get the data that the SP returns into place that I can apply my search criteria?

Ive tried the code below in the SQL Query Analyzer but all I get is:
"Server: Msg 197, Level 15, State 1, Line 10
EXECUTE cannot be used as a source when inserting into a table variable."

DECLARE @TempPropLeads TABLE (
LeadNumber int,
LeadSource char(20) )

INSERT @TempPropLeads (LeadNumber, LeadSource)

EXEC dbo.usp_ReportProposalFromLead NULL ,'2004-06-01', '2004-06-02', NULL

SELECT *
FROM @TempPropLeads
ORDER BY LeadNumber DESC

GO
PS there are more fields returned from the SP - just using the above as a test.

Once I have got the data filtered/sorted as needed it's going to go into a Excel CSV spreadsheet

Cheers

View 7 Replies View Related

MS Access- TOP / Offset? I Need To Order Results As Pages

Feb 18, 2005

Hi,

Sorry I have to post this here, but its sort of related to MS SQL anyway

I'm running a PHP system with MS Access. I need to order results in pages. (For those who are familiar with MySqL and Postgresql - I need the equivalent to LIMIT/OFFSET in MS Access).

I know I can "SELECT TOP 50" in my sql - so that solves the number of results per page.
But what about page 2,3,4..etc.... how do I select results from an offset?

There doesnt seem to be a solution for it

Thanks!

View 2 Replies View Related

SQL Server 2012 :: Get Results In A Specific Order?

Sep 11, 2014

I have a simple example of what I am trying to do. Here is some code to make a quick table to demonstrate:

create table #students
(
lastname varchar(50)
,firstname varchar(50)
,address1 varchar(50)

[Code].....

I want to select all the records, and them them be in alphabetical order first by lastname, then by firstname, then by address. HOWEVER, and this is the tricky part, I want to group names together that have the same address. So, in this example, I want the results to be in this order:

HallC6309 N Olive
HallP6309 N Olive <---- grouped with the C record because they have the same address
HallE5488 W Catalina <---- back to alphabetical by first name
HallJ7222 N Cocopas

View 7 Replies View Related

Brain Teaser - Stagger The Order Of The Results

Sep 5, 2005

This one has been stumping me for several days. I can run a query thatreturns several different items from several different manufacturers,each with a ranking score. Each manufacturer can have any number ofitems:Item_Name Manufacturer rankItem 1 Manu_A 82Item 2 Manu_A 65Item 3 Manu_A 41Item 4 Manu_B 32Item 5 Manu_C 21Item 6 Manu_B 19However, I would like the records to be ordered so that the highestranking item is shown first, then the next highest item from adifferent manufacturer is shown second, then the next highest item froma third manufacturer is show, etc.:Item 1 Manu_A 82Item 4 Manu_B 32Item 5 Manu_C 21Item 2 Manu_A 65Item 6 Manu_B 19Item 3 Manu_A 41Does anyone have any thoughts on how to order the results in thisfashion?thanks,Matt Weiner

View 2 Replies View Related

3 Results From One Field - Show Levels In Right Order

Nov 19, 2007


Hi there

We have a web application (database) that uses one field called Application and another called TicketType.

When a user fills out a ticket they can choose up to 3 levels of this field.
Eg Application, Application2, Application3

Eg TicketType, TicketType2, TicketType3

The extra two levels not being compulsory.

I am using sql server 2005 // Reporting Services

My query is as below:
SELECT Ticket.TicketNumber, Ticket.CreatedDate, Application_2.ApplicationName AS Application, Application_1.ApplicationName AS [App 2],
Application.ApplicationName AS [App 3], TicketType_2.TicketTypeName AS Tickettype, TicketType_1.TicketTypeName AS [Type 2],
TicketType.TicketTypeName AS [Type 3], Ticket.Description, Company.CompanyName
FROM Ticket INNER JOIN
TicketType AS TicketType ON Ticket.TicketTypeID = TicketType.TicketTypeID LEFT OUTER JOIN
TicketType AS TicketType_1 ON TicketType.ParentTicketTypeID = TicketType_1.TicketTypeID LEFT OUTER JOIN
TicketType AS TicketType_2 ON TicketType_1.ParentTicketTypeID = TicketType_2.TicketTypeID INNER JOIN
Application AS Application ON Ticket.ApplicationID = Application.ApplicationID INNER JOIN
Company ON Application.CompanyID = Company.CompanyID FULL OUTER JOIN
Application AS Application_1 ON Application.ParentApplicationID = Application_1.ApplicationID FULL OUTER JOIN
Application AS Application_2 ON Application_1.ParentApplicationID = Application_2.ApplicationID
WHERE (Ticket.CreatedDate >= @StartDate)
ORDER BY Ticket.TicketNumber



End result looks like this:





Application

App 2

App 3

TicketType

Type 2

Type 3


Software

Internal Apps

proACT





SW Other






Office Issues





General




Application

Click Track server



Alert (App)

Service




Network

Other





Network Fault


Software

Internal Apps

Other



User Account

New




Hardware

Network





HW Fault




Application

Click Track server



Alert (App)

Disk space






Office Issues





General






proACT



Configuration

Deployment


Software

Server Software

SharePoint



SW Fault

App Failure (Function)


Software

Server Software

SharePoint



SW Fault

App Failure (Function)


Ultimately I would like the Application (TicketType) fields to have the Master Information in it and the other two fields populated in order as well.

Can someone help please.


Please ask if I haven't explained myself.

thanks
Dianne

View 9 Replies View Related

Best Way To Order Results Sequentially Starting From Somewhere In The Middle

Apr 19, 2007

I'm working with SQL Server 2005, and I'm trying to sort the results based on a user selected letter. Say the user selects 'D' to filter his results. I'd like to return the results starting from D followed by E, F, G...Z, A, B, C. What I'm getting is the results for the D entries at the top of the result set, followed by A, B, C, E...Z.

A solution comes to mind that would be very long and db intensive, by querying on 'like 'D', followed by like 'E', followed by like 'F', etc, but I'm sure that there is a much more efficient way to do this. Below is the code that I'm using now.





' where @SortString = 'd' and @Test is a temp Table



BEGIN

Insert into @Test

Select CompanyName,ContactId, CompanyId

from vContacts where CompanyName like @SortString +'%'

Order by CompanyName



Insert into @Test

Select CompanyName,ContactId, CompanyId

from vContacts where CompanyName not like @SortString +'%'

Order by CompanyName

END



Thanks in advance for your help

View 3 Replies View Related

Extract Distinct Information And Order The Results

Sep 24, 2007

Hi,

MSSQL 2000 T-SQL

I have a problem in extracting information pertaing to a key value and matching that key value to another transaction but the order is based on another value in the same row.


I've attached a sample of DB data below.

tran_nr ret_ref_no msg_type description
5111 12345 420 reversal
5112 12345 200 auths
5113 15236 200 auths
5114 46587 200 auths
5115 46587 420 reversal

Requirement using the above data is to extract data where the ret_ref_no is the same for more than one row but also check that the msg_type 420 happens before the 200. Is there a way of retrieving the information in this way using the tran_nr coloumn values? The tran_nr values is basically the serial number when the transaction is wrriten away to the DB.

I've managed only to retrive the 1st half of my query whereby the same ret_ref_nr is being used by more then one transaction. Still need to figure out the 2nd part where the msg_type of 420 happens before the 200.


SELECT * FROM SAMPLE
WHERE ret_ref_no in
(
SELECT ret_ref_no FROM SAMPLE
GROUP BY ret_ref_no HAVING COUNT(*) > 1
)

Results of query
5111 12345 420 reversal
5112 12345 200 auths
5114 46587 200 auths
5115 46587 420 reversal

If someone could assist with only retreiving the above results in bold to the query analyser i will really appreciate it.

Regards
Deceptive

View 9 Replies View Related







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