473,385 Members | 1,720 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,385 software developers and data experts.

How to check for the value before you select it

This is what i am trying to do:



Table dbo.Customers



Name: Address :

Charlie 12344

Mik 12254

Steven 12545

AJ 12456



in my stored procedure: I want to select the column name and the address so I will have

select name, address from



* the question is how can I check if the name is Mike i want to replace it with Chris

so i am trying to do something like that

select if(name)='Mike' then i want to replace it with Chris, also if the name is =’AJ’ I want to replace it with ‘Sarah’,

address from Customers



how can I check the value before I select it in my stored procedure



Thank you
Sep 19 '07 #1
4 1420
ck9663
2,878 Expert 2GB
This is what i am trying to do:



Table dbo.Customers



Name: Address :

Charlie 12344

Mik 12254

Steven 12545

AJ 12456



in my stored procedure: I want to select the column name and the address so I will have

select name, address from



* the question is how can I check if the name is Mike i want to replace it with Chris

so i am trying to do something like that

select if(name)='Mike' then i want to replace it with Chris, also if the name is =’AJ’ I want to replace it with ‘Sarah’,

address from Customers



how can I check the value before I select it in my stored procedure



Thank you
try something like:

Expand|Select|Wrap|Line Numbers
  1. select case when name = 'MIKE' then 'CHRIS' when name = 'AJ' then 'SARAH'
  2. as name, address from dbo.Customer
the problem with this is you will have a record with name = 'CHRIS' having Mike's Address. is this what you're trying to do?
Sep 20 '07 #2
debasisdas
8,127 Expert 4TB
As you have posted a question in the articles section it is being moved to SQL Server Forum.


MODERATOR.
Sep 20 '07 #3
try something like:

Expand|Select|Wrap|Line Numbers
  1. select case when name = 'MIKE' then 'CHRIS' when name = 'AJ' then 'SARAH'
  2. as name, address from dbo.Customer
the problem with this is you will have a record with name = 'CHRIS' having Mike's Address. is this what you're trying to do?
Thank you for your help, Now i am trying to do something like that



select FName(also i need to select the address)

if (SUBSTRING(FName, 1, 4)='Rani')

BEGIN

Replace(FName,'Rani','PO_Rani')


END

if (SUBSTRING(FName, 1, 3)='Cha')

BEGIN

Replace(FName,'Cha','PO_Rani')


END


from test1Users

thie is the error i get
Incorrect syntax near 'Replace'.


I tried to use the Case Statement but it did not work too



Thank you for your help
Sep 20 '07 #4
rob313
16
There was a synax error in the case statement. Try this

SELECT
CASE
when name = 'MIKE' then 'CHRIS'
when name = 'AJ' then 'SARAH'
else name
END as name
,address
FROM dbo.Customer
Sep 20 '07 #5

Sign in to post your reply or Sign up for a free account.

Similar topics

3
by: Mohammed Mazid | last post by:
Hi folks! Can anyone please help me with this? I am developing a Quiz program but I am stuck with "multiple answers". Basically I need some sort of code that would select multiple answers...
20
by: | last post by:
If I need to check if a certain value does exist in a field, and return either "yes" or "not" which query would be the most effestive?
1
by: Luis | last post by:
Is there an easier way to check if any of the fields returned in a select statement have null values? After running this command: set rs = conn.execute("select A,B,C,D,E,F,G,H,I,J from...
2
by: Stephen Miller | last post by:
I have a page with many, dynamically generated combo boxes and I want to check all of them, before I add a unique value to specific combo. What would be the best way to work through the document...
2
by: jimi_xyz | last post by:
Sorry if this isn't the correct group, i don't think there is a group for straight HTML. I am trying to create a type of search engine. There are two radio buttons at the top, in the middle there...
2
by: Travis.Box | last post by:
I have an MS Access userform with 16 Check Boxes. Each of the checkboxes has a different option value, which coincides with the Check Box name (eg. cb01.OptionValue = 1). At the bottom of the...
1
by: scprosportsman | last post by:
Please help guys, i am trying to set up a database here at work and im fairly new to access in terms of writing functions and queries and stuff. I have 2 different places on my design that will...
3
by: yakuza | last post by:
hi, i want to know how to clear select boxes if i unselect a check box. sample of form code <input type="checkbox" name="truk" value="5"> <select name="day"> <option value=""></option>
6
by: D | last post by:
Hello all...I have an issue with one of my java script functions that I'm hoping someone can easily help with. I have a web based application that we use to create/sign up for overtime. When we...
2
by: qwedster | last post by:
Folk! How to programattically check if null value exists in database table (using stored procedure)? I know it's possble in the Query Analyzer (see last SQL query batch statements)? But how...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.