Solved

sort text column

Posted on 2011-02-24
3
509 Views
Last Modified: 2012-06-21
CREATE TABLE [dbo].[sitedata](
      [productid] [int] NULL,
      [pathid] [int] NULL,
      [accessoryid] [int] NULL,
      [alternatecolors] [varchar](100) COLLATE SQL_Latin1_General_CP1_CI_AS NULL,
      [description] [text] COLLATE SQL_Latin1_General_CP1_CI_AS NULL,
      [specifications] [text] COLLATE SQL_Latin1_General_CP1_CI_AS NULL,
      [features] [text] COLLATE SQL_Latin1_General_CP1_CI_AS NULL,
      [itemincludes] [text] COLLATE SQL_Latin1_General_CP1_CI_AS NULL,
      [accessories] [text] COLLATE SQL_Latin1_General_CP1_CI_AS NULL,
      [infoandguides] [text] COLLATE SQL_Latin1_General_CP1_CI_AS NULL,
      [rebateinfo] [text] COLLATE SQL_Latin1_General_CP1_CI_AS NULL,
      [sunshineactive] [int] NULL,
      [sunshineprice] [money] NULL,
      [sunshinefeed] [int] NULL,
      [pyxisactive] [int] NULL,
      [pyxisprice] [money] NULL,
      [pyxisfeed] [int] NULL,
      [hdewactive] [int] NULL,
      [hdewprice] [money] NULL,
      [hdewfeed] [int] NULL,
      [shippingtype] [varchar](50) COLLATE SQL_Latin1_General_CP1_CI_AS NULL,
      [shippingpriceground] [money] NULL,
      [shippingprice3day] [money] NULL,
      [shippingprice2day] [money] NULL,
      [shippingprice1day] [money] NULL,
      [shippingpricetruck] [money] NULL,
      [shippingpricetruckexpress] [money] NULL,
      [shippingpricetruckwhite] [money] NULL,
      [pyxispackages] [varchar](1000) COLLATE SQL_Latin1_General_CP1_CI_AS NULL,
      [sunpackages] [varchar](1000) COLLATE SQL_Latin1_General_CP1_CI_AS NULL,
      [ebaydescription] [text] COLLATE SQL_Latin1_General_CP1_CI_AS NULL,
      [pdescription] [text] COLLATE SQL_Latin1_General_CP1_CI_AS NULL
) ON [PRIMARY] TEXTIMAGE_ON [PRIMARY]



select * from sitedata
order by accessories desc

Msg 306, Level 16, State 2, Line 1
The text, ntext, and image data types cannot be compared or sorted, except when using IS NULL or LIKE operator.


select * from sitedata
where accessories are not null
Msg 4145, Level 15, State 1, Line 2
An expression of non-boolean type specified in a context where a condition is expected, near 'are'.





this is what one column has it in it for one row
147276,146588,147137,146586,147371,148941,148942,148943,148944,148945,3770,148951,2057,148899,148934,148938,3652,148918,148914,148921,31701,147445,148929,148930,148927,148928,148926,53,21063,146066,147141,147213,147372,147373,147290,145762,1079,57,147191,147423,54,55,147139
0
Comment
Question by:rgb192
3 Comments
 
LVL 32

Expert Comment

by:ewangoya
ID: 34974359

You can not sort using a field of type  [text]
You can change the field to a long varchar
0
 
LVL 22

Accepted Solution

by:
pivar earned 500 total points
ID: 34974415
Hi,

You can't order a text field however you can convert it to a varchar(max)

like


select * from sitedata
order by convert(varchar(max), accessories) desc

the second statement should read

select * from sitedata
where accessories is not null

/peter

0
 

Author Closing Comment

by:rgb192
ID: 34975512
thanks
0

Featured Post

Do You Know the 4 Main Threat Actor Types?

Do you know the main threat actor types? Most attackers fall into one of four categories, each with their own favored tactics, techniques, and procedures.

Join & Write a Comment

In this article I will describe the Copy Database Wizard method as one possible migration process and I will add the extra tasks needed for an upgrade when and where is applied so it will cover all.
In this article we will get to know that how can we recover deleted data if it happens accidently. We really can recover deleted rows if we know the time when data is deleted by using the transaction log.
Here's a very brief overview of the methods PRTG Network Monitor (https://www.paessler.com/prtg) offers for monitoring bandwidth, to help you decide which methods you´d like to investigate in more detail.  The methods are covered in more detail in o…
Polish reports in Access so they look terrific. Take yourself to another level. Equations, Back Color, Alternate Back Color. Write easy VBA Code. Tighten space to use less pages. Launch report from a menu, considering criteria only when it is filled…

757 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

21 Experts available now in Live!

Get 1:1 Help Now