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
 Transact-SQL (2005)
 Is this correct?

Author  Topic 

shapper
Constraint Violating Yak Guru

450 Posts

Posted - 2007-03-09 : 20:27:32
Hello,

I have a table where two of the columns are BoxId (UniqueIdentifier) and BoxName (NVarchar). I need to change the BoxName given the BoxName:

@BoxName NVARCHAR(200),
@NewBoxName NVARCHAR(200),
@Feedback INT OUTPUT

AS
BEGIN
SET NOCOUNT ON

IF EXISTS (SELECT * FROM dbo.Boxes WHERE LOWER(BoxName) = LOWER(@BoxName))

BEGIN

UPDATE dbo.Boxes
SET
BoxName = @NewBoxName,
WHERE LOWER(BoxName) = LOWER(@BoxName)

SELECT @Feedback = @@ERROR
END

My question is, can I "rename" the box name and at the same time use the BoxName to select the record?

Thanks,
Miguel

harsh_athalye
Master Smack Fu Yak Hacker

5581 Posts

Posted - 2007-03-09 : 20:58:39
You mean the way you are doing it in update? Yes, it is allowed. Also, if you don't have case-sensitive collation, you can get rid of LOWER() in the WHERE clause.

Harsh Athalye
India.
"The IMPOSSIBLE is often UNTRIED"
Go to Top of Page

khtan
In (Som, Ni, Yak)

17689 Posts

Posted - 2007-03-09 : 21:38:32
Yes. Is it not working as expected ?


KH

Go to Top of Page

mk_garg20
Constraint Violating Yak Guru

343 Posts

Posted - 2007-03-13 : 00:19:49
i dont think u need to use this
IF EXISTS (SELECT * FROM dbo.Boxes WHERE LOWER(BoxName) = LOWER(@BoxName))


mk_garg
Go to Top of Page
   

- Advertisement -