如何获得这一结果. [英] How to get ouput of this.

查看:80
本文介绍了如何获得这一结果.的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

以下语句的结果是什么?

What will be the result of the following statement?

DECLARE @TodaysDate VARCHAR(10)
SET @TodaysDate = '12/25/2005'
SET @TodaysDate = @TodaysDate + 5



//OPTION
A.12/25/2010
B.2005年12月30日
C.04/25/2006
D.生成错误.


这个qns在面试中问我.答案是(D).但是我如何检查它的输出.



//OPTION
A. 12/25/2010
B. 12/30/2005
C. 04/25/2006
D. An error is generated.


This qns asked me in interview . Ans is (D). But how can i check the out put of this.

推荐答案

您编写的查询将给出从varchar到int的转换错误. 如果您想要varchar值,请从您提到的日期开始删除单引号

The query you wrote will give conversion error from varchar to int..
remove the single quotes from the date you mentioned if u want the varchar value

DECLARE @TodaysDate VARCHAR(10)
SET @TodaysDate = 12/25/2005
SET @TodaysDate = @TodaysDate + 5


在sql server查询分析器上执行sql.
答案是D,因为您不能添加字符串值和整数值.
Execute the sql on sql server query analyser.
Answer is D because you can not add string value and an integer value.




打开SQL服务器,然后将此代码复制到查询分析器,然后执行,

在这里您将得到类似的错误.

将varchar值"12/25/2005"转换为数据类型int时,转换失败.
Hi,

open SQL sever then copy this code to query analyzer then execute,

Here you will get the error like.

Conversion failed when converting the varchar value ''12/25/2005'' to data type int.


这篇关于如何获得这一结果.的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆