i have account table which consists of account name,card no
and card no consists 16 digits now i want to retrieve the
data if card no starts from 4 then it should print visa and
if it starts from 5 then it should print master so plse help
me to write simple query with out store procs .

Answers were Sorted based on User's Feedback



i have account table which consists of account name,card no and card no consists 16 digits now i wa..

Answer / rajesh bhawsar

select name,
(case left(cardno,1)
when '4' then 'visa'
when '5' then 'master'
end) as result from account

Is This Answer Correct ?    5 Yes 1 No

i have account table which consists of account name,card no and card no consists 16 digits now i wa..

Answer / rahul

hi every one.

select name,
case
when card_no like'4%' then 'visa'
when card_no like'5%' then 'master'
end result from account;

Is This Answer Correct ?    4 Yes 1 No

i have account table which consists of account name,card no and card no consists 16 digits now i wa..

Answer / kiranu

Hi every one

select name, cardno(case substring(cardno,1,1)when '4' then
'Visa' when '5' then 'Master' end) as Result from account;

Is This Answer Correct ?    1 Yes 0 No

Post New Answer

More SQL Server Interview Questions

What are Sql Reporting Services and analysis services? Can u Explain

1 Answers  


What is partitioned view?

0 Answers  


Suppose i have a table that contains 5 columns like col1,col2...colm5.I want to import only two column through BCP utility.How to do same through BCP in sybase.

0 Answers   HCL,


How you can change the database name in SQL SERVER?

0 Answers  


How to select true false based on column value in sql server?

0 Answers  






How will u find the query which is running in some other machine

4 Answers   CarrizalSoft Technologies, IBM,


How many types of subqueries are there in sql server?

0 Answers  


what is the purpose of creating view is sql server 2000

13 Answers   Wipro,


What is the difference between for auto and for nested?

0 Answers  


What are some examples of schemas?

0 Answers  


What are cursors and when they are useful?

0 Answers  


What are the types of normalization?

0 Answers  


Categories