使用STR()将数字转换为字符串时如何保存初始零点 [英] How can I conserve the initial zero when convert numeric to string using STR()

查看:83
本文介绍了使用STR()将数字转换为字符串时如何保存初始零点的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

很抱歉提出一个愚蠢的问题,但是我尝试了很多方法,它们确实工作了



当我尝试转换STR(06)时如何保存初始零点进入

SQL语句中的字符串?

总是给我6而不是06.


非常感谢。

Sorry to raise a stupid question but I tried many methods which did
work.
how can I conserve the initial zero when I try to convert STR(06) into
string in SQL statment?
It always gives me 6 instead of 06.

Thanks a lot.

推荐答案

你不能保留零。整数06 =整数6 =整数

00000000006.

如果要将整数转换为varchar,可以添加0字符

结果:


SELECT''0''+ CAST(06 AS VARCHAR)


返回''06'' 。这种方法的缺点是如果你做了类似的事情


SELECT''0''+ CAST(10 AS VARCHAR)


你''010''最终可能会或可能不是你想要的。你可以使用SUBSTRING函数构建这个例子来获得
,以便得到你真正想要的东西。


< ;一个******* @ gmail.com>在消息中写道

news:11 ********************** @ g10g2000cwb.googlegr oups.com ...
You can''t "preserve" the zero. Integer 06 = Integer 6 = Integer
00000000006.

If you want to convert an integer to a varchar you can prepend a 0 character
to the result:

SELECT ''0'' + CAST(06 AS VARCHAR)

Returns ''06''. The downside to this method is that if you do something like

SELECT ''0'' + CAST(10 AS VARCHAR)

You''ll end up with ''010'' which may or may not be what you want. You can
build on this example with the SUBSTRING function to get exactly what you
really want out of it.

<an*******@gmail.com> wrote in message
news:11**********************@g10g2000cwb.googlegr oups.com...
很抱歉提出了一个愚蠢的问题,但是我尝试了很多方法来完成工作。
当我尝试将STR(06)转换为
字符串时,如何保存初始零点SQL语句?
它总是给我6而不是06.

非常感谢。
Sorry to raise a stupid question but I tried many methods which did
work.
how can I conserve the initial zero when I try to convert STR(06) into
string in SQL statment?
It always gives me 6 instead of 06.

Thanks a lot.



你很困惑带有内部LOGICAL模型的PHYSICAL显示。

这是SQL而不是COBOL。数字中没有初始零;那里

是一个内部二进制文件,BCD或其他任何硬用途表示。


你的下一个问题是你不明白那个显示是不是

在数据库中完成,但在前端应用程序中完成。这是* any *分层架构的最基本概念,而不仅仅是SQL。

You are confusing the PHYSICAL display with the internal LOGICAL model.
This is SQL and not COBOL. There is no initial zero in a number; there
is an internal binary, BCD or whatever the hard uses representation.

Your next problem is that you do not understand that dispaly is NEVER
done in the database, but in the front end application. That is the
most basic concept of *any* tiered architecture, not just SQL.


- CELKO--( jc*******@earthlink.net)写道:
--CELKO-- (jc*******@earthlink.net) writes:
你的下一个问题是,你不明白在数据库中完全没有完成显示,而是在前端应用。这是* any *分层架构的最基本概念,而不仅仅是SQL。
Your next problem is that you do not understand that dispaly is NEVER
done in the database, but in the front end application. That is the
most basic concept of *any* tiered architecture, not just SQL.




只要你在数据库交易中工作就应该有学会了

你永远不要说永远。


至少有一个明显的例子,输出的格式必须是

SQL:在标准查询工具中完成显示时,可以像查询分析器一样使用
。对于管理员来说通常就是这种情况。

-

Erland Sommarskog,SQL Server MVP, es **** @ sommarskog.se


SQL Server 2005联机丛书
http://www.microsoft.com/technet/pro...ads/books.mspx

SQL Server 2000联机丛书
http://www.microsoft.com/sql/prodinf...ons/books.mspx



Working so long as you have done in the database trade should have learnt
you to never say never.

There is at least one obvious case where formatting of output must be
done in SQL: to wit when the display is done in a standard query tool
like Query Analyzer. Which typically is the case for admin stuff.
--
Erland Sommarskog, SQL Server MVP, es****@sommarskog.se

Books Online for SQL Server 2005 at
http://www.microsoft.com/technet/pro...ads/books.mspx
Books Online for SQL Server 2000 at
http://www.microsoft.com/sql/prodinf...ons/books.mspx


这篇关于使用STR()将数字转换为字符串时如何保存初始零点的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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