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 the joins in sql server? : sql server database administration

0 Answers  


Why we need to use secondry database file? though, we can do same work using primary database file also.

2 Answers   Microsoft,


What are the advantages of log shipping?

0 Answers  


Can we join two tables without primary key?

0 Answers  


What is the return type of executeupdate ()?

0 Answers  






How would we use distinct statement? What is its use?

0 Answers  


What is ms sql server service broker?

0 Answers  


What happens if an integer is too big for int date type?

0 Answers  


What command is used to rename the database?

0 Answers  


Explain the microsoft sql server delete command?

0 Answers  


What is shrink log file?

0 Answers  


How to set database to be single_user in ms sql server?

0 Answers  


Categories