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 is cross join in sql server joins?

0 Answers  


Determine when an index is appropriate?

0 Answers  


You notice that the transaction log on one of your databases is over 4gb the size of the data file is 2mb what could cause this situation, and how can you fix it?

0 Answers  


statement (of account) Receive ID_receive Date_receive Amount_receive TO_receive From_receive Description_receive 1 2010/01/01 500 Bank Ahmed Payment from the account 2 2010/02/01 700 Bank Ahmed Payment from the account Payment ID_payment Date_payment Amount_payment From_payment To_payment Description_payment 1 2010/03/01 1000 Ahmed Sales Sale goods 2 2010/04/01 1500 Ahmed Sales Sale goods How can crate Stored Procedures for the statement (of account) from these tables? I want statement (of account) like this: (in sql 2005) ID_ name description debit account credit account balance

1 Answers  


What is use of except clause?

0 Answers  






How do we return a record set from a Stored Procedure in SQl server 2000?

3 Answers  


How to transfer an existing table from one schema to another schema in ms sql server?

0 Answers  


How to find the last update record in SQL Server?

4 Answers  


What are the advantages of user-defined functions over stored procedures in sql server?

0 Answers  


What are the joins in sql server? : sql server database administration

0 Answers  


What is single-user mode?

0 Answers  


What is normalization and its forms?

4 Answers   Challenger Financial,


Categories