| 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 |
 |
|
|
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 |
 |
|
|
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. |
 |
|
|
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 |
 |
|
|
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. |
 |
|
|
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? |
 |
|
|
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.... |
 |
|
|
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 |
 |
|
|
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 KizerMicrosoft MVP for Windows Server System - SQL Serverhttp://weblogs.sqlteam.com/tarad/ |
 |
|
|
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 againPS I think I'm finally getting to grips with BOL...lol |
 |
|
|
madhivanan
Premature Yak Congratulator
22864 Posts |
Posted - 2007-11-21 : 00:51:45
|
| Read about + (String Concatenation) in sql server help fileMadhivananFailing to plan is Planning to fail |
 |
|
|
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 +. |
 |
|
|
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 guysButterfly82 |
 |
|
|
|