x

Not in Select Statement

Hi!

I need to specify in the select statement that the USER_1 field is not equal to 'STD'.

I tried first putting it in the where clause but get an error stating that the multipart statement could not be identified.

How can I specify this in the following select statement?

MAX(LEFT(ISNULL(USER_1,''),50)) AS CODE
more ▼

asked Aug 07, 2012 at 12:54 AM in Default

technette gravatar image

technette
1.2k 86 99 109

Can you please share the full code. It is a bit difficult to help with such less information.
Aug 07, 2012 at 10:53 AM Usman Butt
(comments are locked)
10|1200 characters needed characters left

1 answer: sort voted first

It looks like you have two different questions. The first, how to ensure USER_1 is not equal to 'STD' you do this:

SELECT tn.*
FROM dbo.TableName AS tn
WHERE tn.USER_1 != 'STD'

Obviously I have substituted a table where yours would go.

You can't filter data in the SELECT clause. That is what the WHERE clause is for. If you're getting an error that the name doesn't exist, it suggests that you may have a problem in the code elsewhere.

The second question is around the MAX statement. You will have to make that a part of a GROUP BY query for it to work.

more ▼

answered Aug 07, 2012 at 12:11 PM

Grant Fritchey gravatar image

Grant Fritchey ♦♦
103k 19 21 74

(comments are locked)
10|1200 characters needed characters left
Your answer
toggle preview:

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

New code box

There's a new way to format code on the site - the red speech bubble logo will automatically format T-SQL for you. The original code box is still there for XML, etc. More details here.

Follow this question

By Email:

Once you sign in you will be able to subscribe for any updates here

By RSS:

Answers

Answers and Comments

SQL Server Central

Need long-form SQL discussion? SQLserverCentral.com is the place.

Topics:

x110

asked: Aug 07, 2012 at 12:54 AM

Seen: 467 times

Last Updated: Aug 07, 2012 at 01:01 PM