-1

I want to select a record and with exception to specific fields.

SELECT * FROM tb_Account EXCEPT name="me"

Is there's a statement for that?

Thanks! in advance.

MarckxMan
  • 35
  • 1
  • 8
  • Can you explain a little better what you are trying to do? You want to get all rows that have a name different than 'me'? or a column != 'me'? – Filipe Silva Dec 11 '13 at 15:25
  • If you are trying to provide results that omit sensitive information, e.g. employees without salary, you might want a VIEW. – HABO Dec 11 '13 at 15:40

2 Answers2

0
SELECT * FROM tb_Account WHERE name <> 'me'
David
  • 1,591
  • 1
  • 10
  • 22
0

Something you could do is this:

SELECT 'SELECT ' +
    STUFF ((
        SELECT ', [' + name + ']'
        FROM syscolumns
        WHERE id = OBJECT_ID('tb_Account') AND
            name <> 'me'
        FOR XML PATH('')), 1, 1, '') +
    ' FROM [tb_Account]'

That would generate a SELECT statement. Then you could execute that like this:

DECLARE @sql VARCHAR(MAX)

SELECT @sql = 'SELECT ' +
    STUFF ((
        SELECT ', [' + name + ']'
        FROM syscolumns
        WHERE id = OBJECT_ID('tb_Account') AND
            name <> 'me'
        FOR XML PATH('')), 1, 1, '') +
    ' FROM [tb_Account]'

EXECUTE (@sql)
Mike Perrenoud
  • 66,820
  • 29
  • 157
  • 232