Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Concatenating Dates, but not adding them!! 1

Status
Not open for further replies.

pondo

Programmer
Jun 17, 2000
16
US
there's something I can do in Oracle very easily, but can't seem to accomplish in SQL Server:

Remember in Oracle if you want to have a select statement concatenate you just put || between the field names? Well, with SQL Server I tried using the '+' sign and it won't work because it'll add the two dates together...any ideas?

I already have the select statement looking like the following:

"select Date_Resolved (syntax goes here-not the '+') CAST(getdate()as Datetime) from...." what would I put in between "Resolved" and "CAST"?

I know the cast function is needed for the second part of the query..

I would greatly appreciate if somebody could respond and provide any recommendations..
 
Try converting the returned dates to varchars before concatonating with a +
 
yeah, i can see what you're getting at with this workaround, but that's alot of trouble to do a lousy concatenation! It's not a very brilliant idea to use the '+' symbol, is it? A more neutral character would be much better...
 
It's a "Microsoft standard", which in technical terms is also known as an oxymoron ;)
 
Actually, the double meaning of the '+' symbol shows some Object Oriented abilities, i.e. operator overloading/polymorphism. In English that means that the operator adapts its actions to the situation...when you give it two dates it adds them together, two numbers as well, but two strings can only be concatonated. It means that you don't have to go learning loads (more) special symbols.
 
If concatenation were only done on string fields, then using the + operator would make a lot a sense. However, I use concatenation on other data types as well, so having to convert data types to strings in order to concatenate them is a annoyance, and I view it as a minor defect, not something that makes it easier to use.
 
Amen! The fewer workarounds that would be necessary (i.e. converting to char as a yet another unnecesary one) for us to incorporate, the more automated our programming can be. Avoiding menial programming like this is in a sense one step closer to the ease of reuse objective behind OO...
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top