Solved

SQL Select

Posted on 2014-11-18
2
277 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 14

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 46

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

NAS Cloud Backup Strategies

This article explains backup scenarios when using network storage. We review the so-called “3-2-1 strategy” and summarize the methods you can use to send NAS data to the cloud

Question has a verified solution.

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

In this article I will describe the Detach & Attach method as one possible migration process and I will add the extra tasks needed for an upgrade when and where is applied so it will cover all.
In this article I will describe the Copy Database Wizard method as one possible migration process and I will add the extra tasks needed for an upgrade when and where is applied so it will cover all.
Familiarize people with the process of utilizing SQL Server functions from within Microsoft Access. Microsoft Access is a very powerful client/server development tool. One of the SQL Server objects that you can interact with from within Microsoft Ac…
Using examples as well as descriptions, and references to Books Online, show the different Recovery Models available in SQL Server and explain, as well as show how full, differential and transaction log backups are performed

919 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

Need Help in Real-Time?

Connect with top rated Experts

15 Experts available now in Live!

Get 1:1 Help Now