Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/sql-server/23.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
使用数字和转义字符创建SQL值?_Sql_Sql Server_Sql Server 2008 - Fatal编程技术网

使用数字和转义字符创建SQL值?

使用数字和转义字符创建SQL值?,sql,sql-server,sql-server-2008,Sql,Sql Server,Sql Server 2008,我希望创建一个包含字段和一些转义字符的SQL查询,以便客户端更容易地将数据上传到系统中。 以下是我创建的内容: Select [Int Field], Str("'" + [Int field] + "',") as client field, etc. 该字段运行正常,但拒绝显示特殊字符,只显示字段(尽管以指定的空格为中心),没有数字。当我使用“”时,它不会强制它们出现,但当我分离它显示的字段时 我需要它表现得像 '123123', '123124', '123125',

我希望创建一个包含字段和一些转义字符的SQL查询,以便客户端更容易地将数据上传到系统中。 以下是我创建的内容:

Select
    [Int Field],
    Str("'" + [Int field] + "',") as client field,
etc.
该字段运行正常,但拒绝显示特殊字符,只显示字段(尽管以指定的空格为中心),没有数字。当我使用“”时,它不会强制它们出现,但当我分离它显示的字段时

我需要它表现得像

'123123',
'123124',
'123125',

etc.
有没有办法创建一个SQL查询来输出这样的内容?

str()
有一个可选的
length
参数,默认值为10,一个可选的
decimal
参数,默认值为0。您可以使用
[int field]
len()
,也可以使用
convert(varchar(10),[int field])
将其转换为字符串

此外,在转换之前,不能将字符串添加到
[int字段]

试试这个:

select
    [Int Field]
  , '''' + convert(varchar(10),[Int field])  + ''',' as clientfield
  , '''' + Str([Int field],len([Int field])) + ''',' as clientfield2
...

显示你的代码?@SqlZim我显示了吗?这实际上是一个关于该字段的Select语句,但我将添加它以澄清问题。您使用的是哪个版本的SQL server?