SQL output question | The Moonfrog Lab interview question
Question
SELECT ‘NITIN’+1
SELECT ‘NITIN’+’1’
SELECT(SELECT ‘NITIN’)
SELECT ‘1’+1
SELECT 1+’1’
solved
3
SQL
55 years
18 Answers
2283 views
Grand Master 1
Answers ( 18 )
Sorry it a private answer.
a) 1
b) 1
c)Nitin
d) 2
e) 2
SELECT ‘NITIN’+1: Error (string to, int datatype conversion )
SELECT ‘NITIN’+’1’: NITIN1
SELECT(SELECT ‘NITIN’) : NITIN
SELECT ‘1’+1: 2 (‘1’ can be converted to 1)
SELECT 1+’1’: 2
SELECT ‘NITIN’+1: error (can’t convert string to int)
SELECT ‘NITIN’+’1’: NITIN1
SELECT(SELECT ‘NITIN’): NITIN
SELECT ‘1’+1: 2
SELECT 1+’1’: 2
SELECT ‘NITIN’+1 – Error
SELECT ‘NITIN’+’1’ – NITIN1
SELECT(SELECT ‘NITIN’) – NITIN
SELECT ‘1’+1 : 2
SELECT 1+’1’ : 2
1) Error
2) NITIN1
3) NITIN
4) 2
5) 2
1
1
NITIN
2
2
SELECT ‘NITIN’+1 :- Error
SELECT ‘NITIN’+’1’ :– NITIN1
SELECT(SELECT ‘NITIN’) :– NITIN
SELECT ‘1’+1 :- 2
SELECT 1+’1’ :- 2
ERROR
NITIN1
NITIN
2
2
ERROR
NITIN1
NITIN
2
2
how 2 is answer in last two cases?
1. Error
2. Nitin1
3. Nitin
4. 2
5. 2
1. output: 1
2. output : 1
3. output: NITIN
4. output: 2
5. output: 2
1. 1
2. 1
3. NITIN
4. 2
5. 2
Error
NITIN1
NITIN
2
2
1. Error – Can’t Convert varchar value ‘NITIN’ to Int Datatype
2. NITIN1 – Since both are of string datatype
3. NITIN
4. 2
5. 2
1. Error
2. NITIN1
3. NITIN
4. 2
5. 2
A string cannot be combined with numeric number. Therefore, error.
Then, Nitin1 (in this case ‘1’ implies 1 is now a string)
Then, 2
Then, 2