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
Usually, we use the SQL PRINT statement to print corresponding messages or track the variable values while query progress. We also use interactions or multiple loops in a query with a while or for a loop. We can also use the SQL PRINT statement to track the iteration.
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()
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 ;
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With