Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 SQL Server 2005 Forums
 Other SQL Server Topics (2005)
 "not equal to" in sql statement?

Author  Topic 

KarinElvira
Starting Member

47 Posts

Posted - 2010-09-30 : 06:11:11
Is it possible to write an sql statement that says: update column where ID is NOT equal to thisID? Example:
"UPDATE StartImage SET Publish = '1' WHERE ID != '"+ BildID +"'";
If not - what do I need to do?

Transact Charlie
Master Smack Fu Yak Hacker

3451 Posts

Posted - 2010-09-30 : 06:16:25
not equal to which ID? a parameter passed in? then something like

DECLARE @BildID INT
SET @BildID = 23

UPDATE s SET
[Publish] = '1'
FROM
StartImage AS s
WHERE
s.[Id] <> @BildID

If you meant something else then I think you'll need to give an example with data.

Charlie
===============================================================
Msg 3903, Level 16, State 1, Line 1736
The ROLLBACK TRANSACTION request has no corresponding BEGIN TRANSACTION
Go to Top of Page

KarinElvira
Starting Member

47 Posts

Posted - 2010-09-30 : 06:40:05
OK, I have this table:
[dbo].[StartImage](
[ID] [int] IDENTITY(1,1) NOT NULL,
[ImgPath] [varchar](200) NULL,
[ImgName] [varchar](50) NULL,
[Headline] [varchar](100) NULL,
[Text] [varchar](max) NULL,
[Publish] [int] NULL,

I aslo have one ID that's chosen by a user = BildID. When an ID id chosen it gets the value '0' in clm Publish. There can only be one ID with '0' in Publish so I have to make sure the rest of the ID gets a '1' in Publish. My question is can I find the ID:s that are not BildID? Let me know if I need to clarify this further :)
Go to Top of Page

KarinElvira
Starting Member

47 Posts

Posted - 2010-09-30 : 06:43:19
When an ID id chosen = When an ID is chosen
Go to Top of Page

NeilG
Aged Yak Warrior

530 Posts

Posted - 2010-09-30 : 06:50:01
Can you not have two update statements one which sets everything to 1 in pubish and then one which set the publish to 0 where the id is equal to the users id
Go to Top of Page

KarinElvira
Starting Member

47 Posts

Posted - 2010-09-30 : 06:51:47
Maybe that would be easier, I'll try that and come back with the result.
Go to Top of Page

KarinElvira
Starting Member

47 Posts

Posted - 2010-09-30 : 07:29:52
Yes, it works. Thank you!
Go to Top of Page
   

- Advertisement -