Solved

SQL Select

Posted on 2014-11-18
2
282 Views
Last Modified: 2014-11-19
Hi,

I was trying few queries on SQL server, i just gave the below query and i was baffled with the result it gave.

Query : Select '1' + 1

Result = 2

I was expecting the sql server to throw an error while i try to add varchar 1 ('1') and the integer 1 (1), instead it added both the numbers and returned the result as 2.
Can anyone guide me on my the select query added those 2 numbers and why it did not throw an error.

Thanks in advance,
Rajeeva
0
Comment
Question by:rajeeva_nagaraj
2 Comments
 
LVL 15

Assisted Solution

by:Vikas Garg
Vikas Garg earned 250 total points
ID: 40451624
Hi,

It did not throw error since '1' is valid when it will be converted to int

but however you try to do this with 'a1' it will definitely throw error.
0
 
LVL 49

Accepted Solution

by:
Vitor Montalvão earned 250 total points
ID: 40451754
The engine will always try to convert implicitly if nothing is said and depending on the data types.
You can see in this MSDN article all implicit conversions that SQL Server will try to perform.
0

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Need time in SQL 8 30
Freeze portion of datamart 2 21
SSMS Imprt data from Excel 7 19
SQL Server Error while building a sql query using concatenate statements 3 19
Slowly Changing Dimension Transformation component in data task flow is very useful for us to manage and control how data changes in SSIS.
The Delta outage: 650 cancelled flights, more than 1200 delayed flights, thousands of frustrated customers, tens of millions of dollars in damages – plus untold reputational damage to one of the world’s most trusted airlines. All due to a catastroph…
This video shows, step by step, how to configure Oracle Heterogeneous Services via the Generic Gateway Agent in order to make a connection from an Oracle session and access a remote SQL Server database table.
This video shows how to set up a shell script to accept a positional parameter when called, pass that to a SQL script, accept the output from the statement back and then manipulate it in the Shell.

685 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question