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.
| Author |
Topic |
|
pupli
Starting Member
8 Posts |
Posted - 2008-08-27 : 11:07:41
|
| hello to everybody,I have this query (supliers).Now, I want to look for a specific field.If this field fullfills the specified criteria (e.x. If name = 'John'), than the new query should ADD a new field, next to the target found.for example,The input query (supliers) has 5 fields.Now we want to find all the names 'John', and ADD next to them (that means that we are adding a new column) a special sign (for example 'J')How can this be done ???------------------------If I only could..... |
|
|
khtan
In (Som, Ni, Yak)
17689 Posts |
Posted - 2008-08-27 : 11:13:33
|
use case when . . . KH[spoiler]Time is always against us[/spoiler] |
 |
|
|
Topaz
Posting Yak Master
199 Posts |
Posted - 2008-08-27 : 11:18:48
|
| select * from table_name where field name like 'J%' |
 |
|
|
pupli
Starting Member
8 Posts |
Posted - 2008-08-27 : 11:29:59
|
| Yes khtan, u are right,...can u please give me an example, it doesn't matter if it is related to the one I'm interested.Thanx a lot------------------------If I only could..... |
 |
|
|
pupli
Starting Member
8 Posts |
Posted - 2008-08-27 : 11:31:53
|
| And please remember, that...I have to add a new column to the query, not just asigning values to an excisting field in that query.------------------------If I only could..... |
 |
|
|
khtan
In (Som, Ni, Yak)
17689 Posts |
Posted - 2008-08-27 : 11:39:17
|
[code]select <your existing column here>, new_column = case when name = 'John' then 'J' endfrom < some table >where < some condition > [/code] KH[spoiler]Time is always against us[/spoiler] |
 |
|
|
|
|
|
|
|