Click here to Skip to main content
15,893,668 members
Please Sign up or sign in to vote.
1.00/5 (2 votes)
See more:
SQL
SELECT DBName, ConnString + '#VIJAY#' + FinanceConnString + '#VIJAY#' +
RptDBConnString AS ConStr FROM [DataBase] WHERE Active = 1



select dbname, connstring as ConStr from [database] where active=1


giving same result,so what is the diff between above two queries?Plz explain...

in 1st query why we r using+ '#VIJAY#' + FinanceConnString + '#VIJAY#' +
RptDBConnString
Posted
Comments
Sergey Alexandrovich Kryukov 27-Dec-12 0:43am    
Don't you think this is totally incorrect question, a totally wrong approach to asking question?
You gave a query and ask "why do we use" this or in it. No, you please tell us why do you write it this way. And ask a real question.
—SA
StackQ 27-Dec-12 1:17am    
i m not getting u.But u r senior,so i agree with u,may be approach is not right,but i just want to know diff bet them? And plz help me how should i ask for this question to know diff bet them?

1 solution

The 2 queries will give same result if ConnString column is NULL because
NULL + Anything is NULL.
To see the difference between 2 queries use ISNULL[^]
Try
SQL
SELECT DBName, ISNULL(ConnString,'') + '#VIJAY#' + ISNULL(FinanceConnString,'') + '#VIJAY#' +
ISNULL(RptDBConnString,'') AS ConStr FROM [DataBase] WHERE Active = 1
 
Share this answer
 
Comments
StackQ 27-Dec-12 1:20am    
no,i just want to know why we r using:- +'#VIJAY#' + FinanceConnString + '#VIJAY#' +
in my 1st query,bcoz this query is not written by me,it's written by another person,so i want to know why we r using it?
__TR__ 27-Dec-12 1:27am    
I don't have any idea on why was the query written like that. You may want to check it with the person who actually wrote it.
The + is used for concatenating 2 columns in the query
Take a look at this article
SQL Concatenation[^]
StackQ 27-Dec-12 1:37am    
ya i got my answe:Explaining:-

In my table database(columns are dbname,connstring,financeconnstring,rptdbstring)

by my 1st query it select all connstrings but shows only for dbname and connstring,and remaining exist in background according to 1st query.

but when i run this query:-SELECT + '#VIJAY#' + FinanceConnString + '#VIJAY#' +

RptDBConnString AS ConStr FROM [DataBase] WHERE Active = 1

then it shows all the background/hidden query of financeconnstring and rptdbconnstring.

thnx for ur effort also.
StackQ 27-Dec-12 1:39am    
http://blog.sqlauthority.com/2010/11/25/sql-server-concat-function-in-sql-server-sql-concatenation/

this link helps me.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900