.NET Tutorials, Forums, Interview Questions And Answers
Welcome :Guest
Sign In
Register
 
Win Surprise Gifts!!!
Congratulations!!!


Top 5 Contributors of the Month
Easy Web
Imran Ghani
Post New Web Links

order by sort both select in union

Posted By:      Posted Date: September 22, 2010    Points: 0   Category :Sql Server
 

Hi

I have DropDownList that Show all groups. in that, I want to show "select one group" as default in DDL. for that i used code below. but it sort all return data and "select one group" will not be the first line. How can i fix it?

Best Regards. Morteza

 

	SELECT   -1 as id,'select one group' as groupName
	union
	SELECT   id, groupName
	FROM     [group] 
	order by groupNam



View Complete Post


More Related Resource Links

order by in combination with union

  

 Hi All,

How can I order this by count? so if it appears above and below the union statement, I want it on top

	SELECT distinct BIER.Naam, BIER_L2.L2_Naam, BIER_L3.L3_Naam from BIER_MATCH, BIER, BIER_L2, BIER_L3
	where BIER_L2.L2_ID = BIER.L2_ID and BIER_L2.L3_ID = BIER_L3.L3_ID and BIER.ID = BIER_MATCH.BIER_ID 
	and RECEPT_ID = @RECEPT_ID 

	
	UNION  
	
	--L2
	SELECT distinct BIER.Naam, BIER_L2.L2_Naam, BIER_L3.L3_Naam from BIER_MATCH, BIER, BIER_L2, BIER_L3
	where BIER_L2.L2_ID = BIER.L2_ID and BIER_L2.L3_ID = BIER_L3.L3_ID and RECEPT_ID = @RECEPT_ID 
	and BIER_MATCH.BIER_ID is null


 


What is the meaning of Ascending\descending sort order of a column within an index

  
When I add a new index I can also specify the "sort order" as ascending or descending. What does it mean? does it affect performance? does it mean that the binary search tree will be set in a certain way?

Dynamic Data Entity Framework: Initial Sort Order for Views

  
Hello Steve,I'm trying to set an initial sort order for my View (not table) in Dynamic Data using Entity Framework 2. I have updated my Model and Imported the View. Now I'm trying to use the DisplayColumn attibutebut it's not working.[DisplayColumn("Product", "ParsingOrder", true)]Fabio

Dundas Map - Legend sort order

  
ello, We are using Dundas Maps together with Reporting Services 2008. Now we have come across a problem which we are not able to solve ourselves.   We produce a map showing each countries “ReportingFormat”. The SQL in the background  has the “order by ReportFormat” clause.   The values available in “ReportFormat” are shown in the legend. So far everything looks fine and the values within the legend are ordered correctly (E2B, Intdis, Not specified). See the picture http://img340.imageshack.us/i/correctorderfrompreview.jpg/   We therefore deploy the report and open it up in Internet Explorer but now the order of the legend has changed and is shown as (Intdis, Not specified, E2B). See the picture http://img816.imageshack.us/i/incorrectorderfromie.jpg/   We have tried to set the sorting also within the map (not only within the SQL) but the same problem remained although we are not sure we set that sorting correctly . We are not sure that we found the series collection where we could set the sort order. It is all a bit confusing when working with the maps.   As a final solution we tried to change the available values in “ReportFormat” but then the order was even more confusing. See table below; Available values (ReportFormat) Order in legend in Visual studio preview Order in legend in Internet

Multiple Order by clauses with Union

  

I'm trying to figure out how to run this code, I have over 40 tables that I need to get data from, the only thing I can think of is to use "Union" , I need to get the last record in each table by StartTS (StartTimeStamp) so I figured the best approach is to use "Select Top (1) and use Order by StartTS to get the data.  This works great if you are only grabbing data from 1 table, however like I said I need to grab from over 40. 

My example uses only 2 tables:

SELECT   TOP (1)
             (SELECT   [Unit Name]
              FROM     dbo.UnitVerificationData
              WHERE   (Unit_Code = dbo.CP_BCELP.Unit_Code)) AS UnitName, Operation_type, StartTS, StopTS
FROM     dbo.CP_BCELP
ORDER BY StartTS DESC
UNION
SELECT   TOP (1)
             (SELECT   [Unit Name]
              FROM     dbo.UnitVer

SSRS 2005 and Sort Order

  
I have a table and want to sort the 1st column which is called "WorkType" in a particular order. At present it looks like this.


Type
Admin Tasks
Leave & Public Holiday
Projects

ORDER BY items must appear in the select list if SELECT DISTINCT is specified

  

Hi, i am using a query to get DISTINCT hotels from my Database table sorted by Price and it returns me same hotel times of record found by Price if i use this Query

SELECT distinct(hotelname), availstatus, hoteladdress, hotelphonenumber, hotelpostalcode, destination, starrating, imageurl, hotelcode, TempSession, HotelType, MinimumNightRate from HproTemp where TempSession = '12-53-37' ORDER BY MinimumNightRate

and i get the error "ORDER BY items must appear in the select list if SELECT DISTINCT is specified" When i remove MinimumNightRate from SELECT LIST.

Can anyone have any idea how may i resolve it..


managed metadata sort order for swedish

  

Sort order for managed metadata is not as expected, for instance Swedish letters Å and Ä are sorted as A

The properties for the standard language is set to swedish and explicit sort order is not set.

Is this a bug, or are we doing something wrong?

Installed:

Microsoft SharePoint Server 2010 (14.0.4763.1000)

Language Pack for SharePoint, Project Server and Office Web Apps 2010 - Swedish/svenska (14.0.4763.1000)


Persist sort order in datagrid

  

Hi,

I've got multiple datagrids in the application I'm currently working on. Their ItemSource can be updated with new content on server notifications. When this happens, the ItemSource is being replaced by a new one (would it be better to update the content of the ItemSource - which is much more complicated for this case of figure - instead of binding a new one?)

When the new ItemSource is being bound, the sorting of the grid is being lost. I've solved this behaviour by saving the sorting before setting the new binding and restoring it after the new binding has been done. Below you'll find the static methods used for that:

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Linq;
using System.Windows.Controls;
using System.Windows.Data;
using Telecontrol.SIPPR.Client.Commons.DataObjects;

namespace Telecontrol.SIPPR.Client.Commons.Utils
{
  public static class DataGridUtil
  {
    

ORDER BY items must appear in the select list if SELECT DISTINCT is specified

  

why am i getting the error message when both ORDER BY items appear in the SELECT query?

 

Query

SELECT DISTINCT
B.CreatedDate,
BI.DateFrom,
	CONVERT(VARCHAR(8),BI.DateFrom ,3) as FFromDate,
	CAST(FLOOR( CAST( BI.DateFrom AS FLOAT ) ) AS DATETIME) as FromDate,
	CONVERT(VARCHAR(8),B.CreatedDate ,3) as FBookingDate,
	CAST(FLOOR( CAST( B.CreatedDate AS FLOAT ) ) AS DATETIME) as BookingDate,
	P.BookingRef,
	P.PaymentTypeCode,
	(C.Forename + CASE 

SharePoint 2010 library sort order is incorrect.

  

When sorting by name in a SharePoint 2010 library, numeric results are sorting incorrectly. For instance "122_Test" will sort in front of "13_Test". I know at one point years ago Windows Explorer had the same issue, but when viewing the same library by using the Open with Explorer option, Windows Explorer correctly displays the results. Has anyone encountered this issue, and if so have you found a fix?

Thanks


Tim Vander Kooi

select top 3 order by problem

  

Hi all

 

I want get the last 3 tags that added to the db.

 

My Tag table schema is:

 

TBL TAG:

CREATE TABLE [dbo].[tblTag](

      [TagId] [int] IDENTITY(1,1) NOT NULL,

      [Header] [nvarchar](200) NULL,

      [IsActive] [tinyint] NULL DEFAULT ((0)),

      [Ordered] [int] NOT NULL DEFAULT ((1)),

      [Language] [nvarchar](5) NULL,

      [DateTime] [smalldatetime] NULL,

      [Official] [nvarchar](max) NULL,

      [LastUpdate] [datetime] NULL,

      [Locked] [tinyint] NULL,

      [LastUpdateUser] [nvarchar](256) NULL,

      [NumViews] [bigint] NULL,

      [AllUserModified] [nvarchar](max) NULL,

 CONSTRAINT [PK_tblTag] PRIMARY KEY CLUSTERED

(

      [TagId] AS

In RB 2.0 how to sort in ascending/descending order as default?

  
I have column say of Provider Type which I want to be ordered when report is run so that all other columns are ordered according to the order of the Provider Type values.

Insert into select order of execution

  

If I have the following query

INSERT INTO Table1
SELECT Column1 FROM Table2
How is it executed? Is the Select completed and stored in tempdb then inserted into Table1? Or does it select a row/batch then insert it going back and forth as the result set from the select statement is built?


WPF: how to make a GridView only sort on one column as ascending order?

  

We use GridView inside the Listview. We need the grid view alwasy sort on one column ascending order and not allow to click column header to change it.

Is there a easy way to achieve it in Xaml?

If not possible, how to achieve it in code behind?

thx!

 


Using UNION with ORDER BY

  

It is interesting but when I try to execute query with union word and ORDER BY like that:

Select EmpId, OrderDate, OrderId
From [TestSQL].[Sales].[Orders]
INTERSECT 
SELECT TOP 2 EmpId, OrderDate, OrderId From [TestSQL].[Sales].[Orders] WHERE EmpId=3
ORDER BY OrderDate DESC
UNION
Select EmpId, OrderDate, OrderId
From [TestSQL].[Sales].[Orders]
INTERSECT 
SELECT TOP 2 EmpId, OrderDate, OrderId From [TestSQL].[Sales].[Orders] WHERE EmpId=5
ORDER BY OrderDate DESC
I get the mistake:

Incorrect syntax near the keyword 'UNION'.

But when I use derived table like that :

Categories: 
ASP.NetWindows Application  .NET Framework  C#  VB.Net  ADO.Net  
Sql Server  SharePoint  Silverlight  Others  All   

Hall of Fame    Twitter   Terms of Service    Privacy Policy    Contact Us    Archives   Tell A Friend