9

I want to select a value from my customers datatable. I have been asked this question in an interview.

Select cust_Name from customers where cust_Id=5;

will result as Naresh.

Now I want to print the value as

Customer Name is Naresh

How can I print the value like this.Thank you

2
  • 5
    The usual approach would be to learn TSQL... Commented May 15, 2013 at 4:19
  • Concatenate is the term you might need :) Commented May 15, 2013 at 4:29

3 Answers 3

16
Select 'Customer Name is ' + cust_Name from customers where cust_Id=5;

Or

Declare @CustomerName varchar(50)
Select @CustomerName = cust_Name from customers where cust_Id=5;
Print 'Customer Name is ' + @CustomerName ;
Sign up to request clarification or add additional context in comments.

2 Comments

Thought that there will some statement like print :)
Thanks for showing two different ways in printing statement in SQL.
2

You can declare them

Declare @CstName nvarchar(100)
Select @CstName = cust_Name from customers where cust_Id=5;
Print 'Customer Name is ' + @CstName ;

This is the bettre way while using TSQL as you asked

Comments

2

You can use concat()

Select concat('Customer Name is',cust_Name) as values from customers where cust_Id=5;

Click here to learn more about concat()

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.