Sort Numerically From An Alphanumeric Column

Aug 9, 2006

Hi,

I need to get Sort numerically from an alphanumeric column

Regards,
Kihsore

View 3 Replies


ADVERTISEMENT

Sorting Numerically, And Alpha Numerically

Jan 17, 2007

Hi,

I'm hoping there is an easy way to deal with this....

I have a UNION query. The first SELECT in the UNION I want sorted by an int, the the second SELECT in the union (same column) I want sorted by a char.

Here's a really basic sample of what I mean:

select dummy_data.test from
(select cast(1 as char) as test
union
select cast(11 as char) as test
union
select cast(2 as char) as test
union
select 'Alpha' as test
union
select 'Bravo' as test) dummy_data
order by test asc

..obviously, I need to cast the INT columns as chars or the UNIONs do not work.

However, the sort will sort the numbers alpha numerically: 1,11,2
(I'm looking for 1,2,11)

Any thoughts?

david.

View 4 Replies View Related

Ordering Varchar Column Numerically

Jul 23, 2005

Is there a preferred way to order a varchar column numerically (for thosethat are numeric), then alphanumerically for all others?I've tried:ORDER BY CASE WHEN IsNumeric(<column_name>) = 1 THEN CONVERT(Float,<column_name>) ELSE 999999999 END;andORDER BY CASE WHEN IsNumeric(<column_name>) = 1 THEN 0 ELSE 1 END, CASE WHENIsNumeric(<column_name>) = 1 THEN CONVERT(Float, <column_name>) ELSE 999999END, <column_name>;Neither of these however give the desired results.Any ideas?Thanks,Frank

View 4 Replies View Related

Dynamic Sort Column And Sort Order Not Working

Aug 7, 2007

I am trying to set sorting up on a DataGrid in ASP.NET 2.0.  I have it working so that when you click on the column header, it sorts by that column, what I would like to do is set it up so that when you click the column header again it sorts on that field again, but in the opposite direction. I have it working using the following code in the stored procedure:   CASE WHEN @SortColumn = 'Field1' AND @SortOrder = 'DESC' THEN Convert(sql_variant, FileName) end DESC,
case when @SortColumn = 'Field1' AND @SortOrder = 'ASC' then Convert(sql_variant, FileName) end ASC,
case WHEN @SortColumn = 'Field2' and @SortOrder = 'DESC' THEN CONVERT(sql_variant, Convert(varchar(8000), FileDesc)) end DESC,
case when @SortColumn = 'Field2' and @SortOrder = 'ASC' then convert(sql_variant, convert(varchar(8000), FileDesc)) end ASC,
case when @SortColumn = 'VersionNotes' and @SortOrder = 'DESC' then convert(sql_variant, convert(varchar(8000), VersionNotes)) end DESC,
case when @SortColumn = 'VersionNotes' and @SortOrder = 'ASC' then convert(sql_variant, convert(varchar(8000), VersionNotes)) end ASC,
case WHEN @SortColumn = 'FileDataID' and @SortOrder = 'DESC' THEN CONVERT(sql_variant, FileDataID) end DESC,
case WHEN @SortColumn = 'FileDataID' and @SortOrder = 'ASC' THEN CONVERT(sql_variant, FileDataID) end ASC  And I gotta tell you, that is ugly code, in my opinion.  What I am trying to do is something like this:  case when @SortColumn = 'Field1' then FileName end,
case when @SortColumn = 'FileDataID' then FileDataID end,
case when @SortColumn = 'Field2' then FileDesc
when @SortColumn = 'VersionNotes' then VersionNotes
end

case when @SortOrder = 'DESC' then DESC
when @SortOrder = 'ASC' then ASC
end  and it's not working at all, i get an error saying:  Incorrect syntax near the keyword 'case' when i put a comma after the end on line  5 i get: Incorrect syntax near the keyword 'DESC' What am I missing here? Thanks in advance for any help -Madrak 

View 1 Replies View Related

Alphanumeric Id Column

Apr 9, 2008

I have set a column called "Anumber", I am
using a computed value to get the PK ID # and
a the letter "A" to it.

('A'+CONVERT([varchar](10),[requestid],(0)))

The above works fine unless I copy a record,
The copied record never displays the correct
value like "A55" it keeps "NULL" as it value.

Is their a better way to achieve a result as
described above ?

I am coming from Foxpro to SQL, Any advice would
be great.

Thanks

View 6 Replies View Related

Convert Column Of Data Alphanumeric To Integer

Nov 14, 2013

I need to convert a column of data from alpha numeric to integer.

I am only querying the tables i.e. i don't have access to actually change the data tables themselves.

CAST or CONVERT throws up an error. Are there any other commands i can use at the query stage?

The data I need to convert is always actually a number. i.e. even though it is recognised as alpha numeric, the figure is a number.

I just need it to be converted to an integer so i can SUM it etc.

View 8 Replies View Related

SQL Server 2012 :: Sorting By Alphanumeric Table Column Of NVARCHAR Datatype

Sep 24, 2015

I am trying to sort my sql resultset by an alphanumeric column of a table which is of NVARCHAR datatype. The sample data is given below:

CREATE TABLE #Activities(activityName NVARCHAR(100))

INSERT INTO #Activities VALUES('Field phase S14-04932-01')
INSERT INTO #Activities VALUES('Phase reporting')
INSERT INTO #Activities VALUES('Phase running')
INSERT INTO #Activities VALUES('RD1')

[Code] ....

The output of the query is like this:

A1
A2
A3
A4
E1 0DAA1
E10
E2 0DAA2

[Code] .....

The output what I require is this:

A1
A2
A3
A4
E1 0DAA1
E2 0DAA2

[Code] ....

View 9 Replies View Related

Interactive Column Sort

Mar 9, 2007



Hi All

I'm Climbing the walls here, does anyone know how to do an interactive sort but keep one of the returned rows pinned at the end of the result set?

i've tried this

=iif(Fields!Item.Value <> "c", 1 ,2) & Fields!Item.Value

Doesn't work to well

Results to Sort

d

e

a

b

c

Sort should return

which works fine on the ascending sort

a

b

d

e

c

with c remaining at the bottom

But i get this on the descending sort

c

a

b

d

e

Thanks in advance

Dave

View 1 Replies View Related

Sort Date Column

Feb 11, 2008



Select distinct (left(date,12)) as startdate from table1

order by startdate desc


Guys what am i doing wrong here??? why is it not sorting the year part??

Sep 30 2005
Sep 29 2006
Sep 29 2005
Sep 28 2007
Sep 28 2006
Sep 28 2005
Sep 27 2007
Sep 27 2006
Sep 27 2005
Sep 26 2007

Thanks

View 16 Replies View Related

Can&#39;t Sort By Clicking Column Header In EM

Jan 18, 2001

My boss wants to know why I can sort information in the Enterprise Manager by clicking the column headings but he can't; like in the Job window clicking status to sort the jobs by status so all of the 'executing' jobs are listed first. I said no problem, let's apply SP2 and that should do the trick. To my chagrin it did not solve the problem. I would appreciate any ideas.

Thanks!

View 2 Replies View Related

How To Sort Data On Based Of Column's Value?

Oct 24, 2007

Hi everybody!

My users need to sort data on base of columns that they select ,the same as sorting in grid but i need it with reporting services.

Thankas in advance.

View 3 Replies View Related

Matrix Column Interactive Sort

Feb 27, 2008

I looked around quite a bit but couldn't get around to the issue I've at hand.
I've a matrix report with one row group and one column group. I want to apply interactive sort so that when a user clicks on the column header based on the values in the column the report is rearranged.


The report shows:

Name 02/02/2008 01/31/2008


Test1 15 12
Test2 9 15

Now if the user clicks on 02/02/2008 then it will show
Name 02/02/2008 01/31/2008


Test2 9 15
Test1 15 12


And toggle if clicked again. Hope I'm clear.

View 5 Replies View Related

Sort COLUMN NAMES Of A Table

Apr 25, 2008

Hi all,

Is there a way i can write a script that will sort the column names of my table?

Example:

Table 1 columns:
First_Name
Last_Name
Address
City
Country


I want to write a script that will sort them like this:

Address
City
Country
First_Name
Last_Name

View 4 Replies View Related

Transact SQL :: Sort Column With Null

Nov 26, 2015

I have column X:

X
-------
1
NULL
4
NULL
2
3

NULLI need to sort this column to get this output: X
-----
1
NULL
2
NULL
3
NULL
4
NULL

What i need to do?

View 7 Replies View Related

Unable To Add Stylesheet On Datagrid's Sort Column

Aug 19, 2006

Hi All,

I am trying to add style-sheet on the sort column of datagrid. I am not able to do that as it takes default font and link comes under it. So can anybody help me to resolve this issue.

Thanks & Regards

Bijay

Web Developer

View 1 Replies View Related

Interactive Column Sort In Reporting Services

Aug 21, 2007

Hi,
I have a report with fiive columns, I have implemented interactive column sorting on the report. I have added a group to the report based on Column 2 and there is a page break by group. Now if I am on the second page ( page break by column 2 ) and sort on column 3(there is no grouping on column 3), the sorting happens but after the sort, the first page is displayed.IS there any way to remain on the same page while sorting?
Thanks in Advance.

View 3 Replies View Related

Manualy Sort Matrix Column Group

Nov 7, 2007

I've done this before, but i cant remember how.

All i want to do is sort this group in a specific way.
I want them to be in this order:


AME01

ASE01

ACO01

ALU01

AOS01

APH01

ATR01

ATE01

ACR06

ACR05

ACR02

ACR03

ACR08

ACR07
What is the code i would put in the sorting expression, for this to take place?

View 3 Replies View Related

Interactive Sort On Column Headers In Matrix

Dec 7, 2007

Hi there,

I'm trying to implement Interactive Soring on the column headers in a matrix in a report. Is it actually possible to do this? I've read several internet posts and stories of implementing the Interactive Sorting in the upper-left corner of the matrix, but this is not what I want, I want to implement it on the column headers .

The goal I'm trying to achieve is to give the user the possibillity to click on a column header to sort the rows below in asc- or descending direction.

Please tell me if this is possible, because all my efforts have not been succesfull! If it's possible, please provide the solution to do this.

If you need more information, please don't hesitate to ask.

Thanks in advance,

Dave Ruijter
BI Consultant

View 3 Replies View Related

How To Write A SQL Query To Sort A Table With The Priority Column As Well?

Jan 16, 2005

Hi,

Anyone can help me for the Sql query?

I want to sort a table with a priority column, e.g. in the following...

Table A
======
value
======
9
3
1
7
4
======

After sorting:

Table A
========
no value
========
1 1
2 3
3 4
4 7
5 9
========


Anyone can help me?
Thanks.

Daniel.

View 1 Replies View Related

Reporting Services :: Custom Sort Column Groups

Jun 3, 2015

Is it possible to do custom sort for a Column Group?

i.e. if the columns are coming out as A   B  C, is it possible to change it B   C   A  (or anything else). 

View 5 Replies View Related

Reporting Services :: Sort Report By Totals Column

Jan 4, 2012

I've created an SSRS report in Report builder and I'm displaying it in SharePoint 2010. What I would need to do is to sort according to my totals -column. My report structure is as follows:

The first and column second columns are the ID and the name of a customer. There are over 35.000 consolidated customers in the database.

The third column is the column which I would like my report to be sorted upon. It gives the sum (Amount_EUR) of all different productlines sold to the customer.

The fourth column in this report design model is the product groups sold to that customer. There over twenty of product groups visible when Running the report.

This is what my report looks like when finished (you'd have to scroll a lot to the right if I took the whole of the report so I cut only a part of it to be visible):

I tried to add a sorting option from the reports Tablix properties and adding this code as the sorting function:

=SUM(Fields!Amount_EUR.Value)

But I'm getting an error:  "A sort expression for the tablix 'Tablix1' includes an aggregate function.  Aggregate functions cannot be used in data row sort expressions."

Ok, so no aggregate functions aren't allowed to the sort.

If I just put:

=Fields!Amount_EUR.Value and sort by that from Z to A(biggest to largest) it doesn't have any effect. The report is still sorted alphabetically by the ParentID.

I've also tried some other code bits, but they all seem to be saying that I couldn't put an aggregate function into the sort expression....but my Total -column is already calculated with a Sum -function....

Is it possible sort my report based on that Total -column? If yes, how? I'm using SSRS 2008

View 4 Replies View Related

SQL Server 2008 :: Multiple Languages In Same Column - How To Sort / Select

Jul 29, 2011

We have a database where the nvarchar columns currently holding English only data. It keeps the training information. Currently the default collation is Latin Case insensitive accent insensitive.

Now we are planning to allow multiple language support. When we go for it, we will upload the data from different languages. Based on user preferences, he/she should be able to query the data (One language at a time).

I am worried on how the existing queries will work if I load all language data in the same database.

For example, some characters in English are used in Norwegian too. But they have different sort order. ALso LIKE conditions too may fail.

So far I thought of few solutions: Add the Collation information along with select , order by clauses. It means we need to add more procedures (one set per collation) The other option is to create new database for each language. Each will have its own collation. The dowside is we need more databases which may lead to more servers and more maintenance work.

View 9 Replies View Related

DB Engine :: BCP Output Is Performing Ascending Sort Based On Values Of First Column

Jun 24, 2015

As bcp does not allow for the column names to be included; I have developed a method for providing the columns. The end result is that two Tables are required for each output; a "ColumnNames" table and the Table that contains the actual data; however the bcp command is sorting the data; why this is happening? 

According to Microsoft, by default bcp will not apply any sorting unless specified.

Here is the command I am using to perform the bcp output: -

SET
@bcpCommand =(select
'bcp "SELECT * FROM GPReports.dbo.MIS001_BCPColumnNames UNION  SELECT * FROM GPReports.dbo.voltemp" queryout '
+ @FilePath+'
-c -t -T')

EXEC
master..xp_cmdshell
@bcpCommand

This is the bcp topic I referred to [URL] ....

View 3 Replies View Related

Power Pivot :: How To Create Incrementing Sub Counter For (sort By Column) Purposes

Nov 16, 2015

I have a table ComponentPeriod. In it we have the combination of a component (e.g. A,B,C ) and a period (2014 Q1, 2014 Q2, 2014 January etc)I want the periods to be in descending order (2015 Q4, 2015 Dec, 2015 Nov, 2015 Oct, 2015 Q3 ... etc) and so I need to create a sequential number series to allow this to happen (as we can only order in the client tools by a single column - and so I guess the technique I'm looking for is used a lot to produce these types of "order by" columns)

I have done this in the past using

Period_Sequence =
calculate
(countrows(Period)
,filter
(Period
, Period[Start_Date] <= earlier(Period[Start_Date])
&& Period[Duration_String] = earlier(Period[Duration_String])
)
)

Which was fine when I was referring to a table where Periods where distinct directly but now I have denormalised this for ComponentPeriod so I need something a little more sophisticated Whats the best way to get a sequence with perhaps some partitions in across a subset of distinct columns (I guess from SUMMARIZE or similar)

E.g. I want

Period_Name, Type, Sequence
2015 Q4, Quarter, 1
2015 Dec, Month, 2
2015 Nov, Month, 3
2015 Oct, Month, 4
2015 Q3, Quarter, 5
2015 Sep, Month, 6
etc

even though there may be multiple records in ComponentPeriod that have the period 2015 Q4, but I want them all to have the value Sequence value of 1? I've got as far as:

Period_Sequence Desc =
calculate
(countrows(summarize(ComponentPeriod, ComponentPeriod[Period_End_Date]))
,filter
( ComponentPeriod
, ComponentPeriod[Period_End_Date] >= earlier(ComponentPeriod[Period_End_Date])
)
)

But this doesn't distinguish between the different types. I need an equivalent of the t-sql -

row_number() over (order by Period_End_Date desc, case when 'P3M' then 1 when 'P1M' then 2 end asc

View 7 Replies View Related

Am Using Sql Server 2005, Column Data Type Is Varchar, How To Write A Query To Sort

Aug 2, 2006

this data. need help
Sort following numbers by asc and desc order

Before query sort
-1.1
-8.8
-15.5
0.0
+0.5
+0.2

Sort asc
+0.5
+0.2
0.0
-1.1
-8.8

Sort Desc
-8.8
-1.1
0.0
+0.2
+0.5












View 5 Replies View Related

How To Sort Table In Sql2000 With Ipaddress(format X.x.x.x) As Column With Nvarchar Datatype In Ascending Order

Apr 19, 2006

How to sort table in sql2000 with ipaddress(format x.x.x.x) as column with nvarchar datatype in ascending order
without using stored procedure

Ex:

Table: netComputers(3 rows)
Column Name: ipAddress (string data type)

ipAddress
0.0.18.1
0.1.1.2
0.0.0.1

Sql query : if I use the query

Select ipAddress from netComputers order by cast( replace(ipaddress,'.','') as numeric(12)) asc

Gives result as :
ipAddress
0.0.0.1
0.1.1.2
0.0.18.1

Where as expected result should be:

ipAddress
0.0.0.1
0.0.18.1
0.1.1.2

View 18 Replies View Related

Alphanumeric Primary Key

Jun 15, 2005

Is it possible to have an auto increment alphanumeric primary key eg A1, A2, A3

Thanks

Paul.

View 1 Replies View Related

Constraints With Alphanumeric

Apr 10, 2008

Hi experts,

I am executing a script to add a column to few tables and drop existing constraints, create new foreign key constraints, indexes etc. After we test this on our development database we have to deliver the script to the customer.
My concern here is, when I have to drop the constraint with the name, I am not able to do it because its been created with alphanumeric char in the constraint name. So I end up getting the constraint name for each table. And moreover,
I wont be able to deliver the same script to the customer as the alphanumeric in the constraint names on the customer's database will be different.

Any suggestions to overcome these alphanumeric in the constraint names?

Thanks much

View 20 Replies View Related

AlphaNumeric Function

Jan 10, 2008

Greetings all,

I have upsized 2 foxpro table to SQL Express.
In table 2 called Orphan I have/had a field that
would autonumber with the letter "U" first.
Example would create a AlphaNumber Like "U00001223"

In Foxpro this is a easy function, But I have been
unable to find a similiar way to do this in SQLEXPRESS.
Foxpro would have you define the field as Unique Number with
template defintion of "U"N8

In SQL I know you can use Numeric on a field for a unique number
but cant find setting to proced number with a "U"

Is this doable is in SQL and does anybody have a
reference point or example they could share ?

Any help would be great and hope my question made sense..

View 8 Replies View Related

WHERE Alphanumeric = Numeric

Dec 20, 2007



All,


I'm having trouble with a query where I need to limit a resultset by comparing (using a WHERE clause) a field that is alphanumeric with one that is numeric. I've tried converting, casting, and case statements, but I either get an overflow error or a big slap on the wrist by SQL Server 2005. Does anyone have any good solutions to this? I've been racking my brain for a while now.

Thanks for the help!
-Scott Mescall

View 3 Replies View Related

Alphanumeric Paging On GridView?

Feb 3, 2007

Hello,
I have a SQL database with about 300 company names and corresponding phone numbers.  I would like to show a list of linkbuttons titled A-Z and when pressed, rebind the sqldatasource so that my GridView will only show company names that start with that letter.
I know there are some examples on codeproject.com, but they are a bit over my head...  besides, I don't mind writing a custom select statement for the OnClick of every linkbutton if that's what I have to do.  Problem is I haven't a clue how to write a select statement that will return items who's first letter matches my desired letter?
 Any idea?
 Thanks,
-Derek
 

View 3 Replies View Related

Alphanumeric Autonumber Primary Key

Oct 26, 2004

Hi there,The age old question of creating a unique alphanumeric value automatically like ABC0001, ABC0002 Is it possible to do this automatically? That is, without having to update it which will slow the db down horribly?

View 4 Replies View Related

Auto Increment Alphanumeric ID

Nov 27, 2014

I'm using SQL 2008 with table [AgentDetails] and fields [IDCode],[FirstName],[LastName],..etc. [IDCode] is alphanumeric [AAA001].

Is it possible to increment both alpha & numeric when new record is inserted. e.g.

AAA001,AAA002......AAA999,AAB000,AAB001,...AAB999,AAC000,AAC001...etc. with a user function or some stored procedure.

View 2 Replies View Related







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