Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 General SQL Server Forums
 New to SQL Server Programming
 Using Pipe like symbols to add parentheses??

Author  Topic 

Butterfly82
Starting Member

30 Posts

Posted - 2007-11-20 : 16:44:49
Hi all,

I was told recently that doing the following:

SELECT ProductName ||' , '|| Category FROM PRODUCTS


would add parentheses around the ProductName field data. However, after trying it out for myself I found it did no such thing.

Does this look familiar to anyone? Is it syntax I have wrong or something?

Butterfly82

Van
Constraint Violating Yak Guru

462 Posts

Posted - 2007-11-20 : 16:56:48
Select '('+ProductName+')' from Products
Go to Top of Page

Butterfly82
Starting Member

30 Posts

Posted - 2007-11-20 : 17:04:39
quote:
Originally posted by Van

Select '('+ProductName+')' from Products



Thanks for the feedback Van. Sorry for the obviously simple question, I looked on BOL before hand but guess I was looking for the wrong thing. I was searching for 'Pipe' etc.

Butterfly82

Go to Top of Page

Van
Constraint Violating Yak Guru

462 Posts

Posted - 2007-11-20 : 17:07:16
If you search for | (not pipe), you will find some stuff in BOL but I don't think it's realated to what you were wanting to do.
Go to Top of Page

Butterfly82
Starting Member

30 Posts

Posted - 2007-11-20 : 17:38:00
Yeah, I've came across it in programming languages such as C etc. with a single pipe (|) being Bitwise Inclusive OR and the double pipe (||) being the Logical OR. As it stands with SQL though I don't know it's meaning, if any.

I checked out BOL once again, just out of curiosity to find the meaning of | relating to SQL or any articles on it but it didn't come up with anything, I must be looking in the wrong place if you say it came up with something when you carried out the same search.

This is the location I carry out my searches from:
http://msdn2.microsoft.com/en-us/library/ms130214.aspx
Go to Top of Page

Van
Constraint Violating Yak Guru

462 Posts

Posted - 2007-11-20 : 17:49:41
I came up with the same thing you said about bitwise and logical OR. I was looking on BOL for 2005. I didn't read it carefully though so it may not even have been talking about t-sql.
Go to Top of Page

Butterfly82
Starting Member

30 Posts

Posted - 2007-11-20 : 17:57:11
Ok, thanks Van.
I have the same issue when it comes to searching for the plus (+) symbol or even ‘concatenation’. I searched for concatenation because that is what it seems to be doing. Is there a name for carrying out:
'('+ProductName+')'

that you know if?
Go to Top of Page

Haywood
Posting Yak Master

221 Posts

Posted - 2007-11-20 : 18:18:01
quote:
Originally posted by Butterfly82

Yeah, I've came across it in programming languages such as C etc. with a single pipe (|) being Bitwise Inclusive OR and the double pipe (||) being the Logical OR. As it stands with SQL though I don't know it's meaning, if any.



|, ~, ^ and & are bitwise operators for SQL Server....

Go to Top of Page

Butterfly82
Starting Member

30 Posts

Posted - 2007-11-20 : 18:59:55
quote:
Originally posted by Haywood
|, ~, ^ and & are bitwise operators for SQL Server....



Thanks for that Haywood, very much appreciated.

Do you know the correct name for this operation in SQL?
'...'+ ... +'...'

for example:
'('+ProductName+')'


Thank you
Go to Top of Page

tkizer
Almighty SQL Goddess

38200 Posts

Posted - 2007-11-20 : 19:43:43
quote:
Originally posted by Butterfly82



Do you know the correct name for this operation in SQL?
'...'+ ... +'...'

for example:
'('+ProductName+')'





+ is used to concatenate strings together. In VB, you use &. In T-SQL, it's +.

Tara Kizer
Microsoft MVP for Windows Server System - SQL Server
http://weblogs.sqlteam.com/tarad/
Go to Top of Page

Butterfly82
Starting Member

30 Posts

Posted - 2007-11-20 : 19:58:16
Thanks T Kizer,

I thought it was to concatenate strings but couldn't find anything on BOL. After your post though I went back and tried again and I found this:

http://technet.microsoft.com/en-us/library/ms175524.aspx

Thanks again

PS I think I'm finally getting to grips with BOL...lol


Go to Top of Page

madhivanan
Premature Yak Congratulator

22864 Posts

Posted - 2007-11-21 : 00:51:45
Read about + (String Concatenation) in sql server help file

Madhivanan

Failing to plan is Planning to fail
Go to Top of Page

LoztInSpace
Aged Yak Warrior

940 Posts

Posted - 2007-11-21 : 03:10:10
|| is the ansi standard for string concatenation. Believe it or not, the use of + is non-standard!
Your query would work in, say, Oracle so maybe you're looking at a port.

Just to clarify - it doesn't add any parethesis or anything, it just does what the + operator does. Others have given you how to put something in parenthesis, but if you want identical results to the original query, simply replace || with +.
Go to Top of Page

Butterfly82
Starting Member

30 Posts

Posted - 2007-11-21 : 09:58:39
LozInSpace, thanks for your feedback, it's great information. I thought || must have had some function in SQL because when I typed it into SSMS it grayed out. I'll be sure to read up on it in more detail and try it out.

Thanks for all your help guys
Butterfly82
Go to Top of Page
   

- Advertisement -