Solved

SQL Select

Posted on 2014-11-18
2
281 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 47

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

Backup Your Microsoft Windows Server®

Backup all your Microsoft Windows Server – on-premises, in remote locations, in private and hybrid clouds. Your entire Windows Server will be backed up in one easy step with patented, block-level disk imaging. We achieve RTOs (recovery time objectives) as low as 15 seconds.

Question has a verified solution.

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

Suggested Solutions

Slowly Changing Dimension Transformation component in data task flow is very useful for us to manage and control how data changes in SSIS.
International Data Corporation (IDC) prognosticates that before the current the year gets over disbursing on IT framework products to be sent in cloud environs will be $37.1B.
Familiarize people with the process of retrieving data from SQL Server using an Access pass-thru query. Microsoft Access is a very powerful client/server development tool. One of the ways that you can retrieve data from a SQL Server is by using a pa…
Via a live example, show how to extract insert data into a SQL Server database table using the Import/Export option and Bulk Insert.

770 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