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 2008 Forums
 Transact-SQL (2008)
 Update Help

Author  Topic 

tooba
Posting Yak Master

224 Posts

Posted - 2012-09-14 : 11:49:36
Hi guys,

Quick question, how i can use case statment in update statement or i can use or not, below is my code

Update Mytable
Set Book = (Select top 1 'Book' +' '+isnull(e.book, 'No Book')
From Table2
Case
When isnull(e.book, 'No Book') like %No Book% then '<font Color = Red>' +e.Book + '</font>' else
'<font Color=Green>'+ e.book + '</font>'
)

Thank You...

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2012-09-14 : 16:33:31
can you explain what you're trying to do here

i cant make out much from code

which table has column book. whats e?
how are tables related?

------------------------------------------------------------------------------------------------------
SQL Server MVP
http://visakhm.blogspot.com/

Go to Top of Page

tooba
Posting Yak Master

224 Posts

Posted - 2012-09-15 : 00:52:09
Sorry it was typo mistake here is my final Query

Update Mytable
Set Book = (Select top 1 'Book' +' '+isnull(book, 'No Book')
From Table2
Case
When isnull(book, 'No Book') like %No Book% then '<font Color = Red>' +e.Book + '</font>' else
'<font Color=Green>'+ book + '</font>'
)

I am updating field Book , IN case Statement i am saying if there is no Book then on front end Color change to Red if there is book Color change to Green. Please let me know if my question is not clear, I want to use this case statement in Update statement.

Thank YOu.
Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2012-09-15 : 01:38:25
why do you need to do formatting in t-sql? it should be done at front end not in t-sql


you have not yet provided the columns by which tables are related

------------------------------------------------------------------------------------------------------
SQL Server MVP
http://visakhm.blogspot.com/

Go to Top of Page
   

- Advertisement -