在sql server中用于存储文本aswellas编号的数据类型 [英] which datatype to be used to store text aswellas number in sql server

查看:83
本文介绍了在sql server中用于存储文本aswellas编号的数据类型的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好,

我的一个表格列包含以下类型的数据。



房间号

G111

1234

2342





这里第一个字母表示楼层号



请告诉我用于存储此类数据的数据类型..



我试过varchar和nvarchar ......但是它们都没有工作..



谢谢..

Hi everyone,
One of my tables column contain the following type of data.

Room No
G111
1234
2342


Here the first letter indicates the floor no.

Kindly let me know which datatype to be used to store this kind of data..

I have tried varchar and nvarchar...but both of them not working..

Thank you..

推荐答案

在varchar(MAX)中,您可以保存任何类型的数据(文本,数字和特殊字符)
In varchar(MAX) you can save any type of data (text ,number & special characters )


注意来自Harsh Oswal的解决方案1是正确的。这不是替代解决方案,而是响应后续评论的附加信息



从excel导入时,如果该表尚不存在,那么SQL将尝试工作根据第一行数据输出列类型。如果该行是数字,那么当您到达以G开头的行时,您将遇到问题。



这个方法...



a)首先定义表模式并导入到该表(而不是允许SQL在导入期间创建表)

OR

b)确保excel数据库中的第一行包含该列中的文本数据(不推荐)



c)数据转换是导入的一部分 - 在VS200-2005中有一个用于DTS导入的向导,在后面的版本中肯定会有一个。
Note Solution 1 from Harsh Oswal is correct. This is not an alternative solution but additional information in response to subsequent comments

When importing from excel, if the table doesn't already exist, then SQL will attempt to work out what the column type should be based on the first row of data. If that row is numeric then you will hit a problem when you get to rows beginning with 'G'.

Ways around this ...

a) Define the table schema first and import to that table (rather than allowing SQL to create the table during the import)
OR
b) Ensure that the first row in the excel database contains textual data in that column (not recommended)
OR
c) Do data transformations as part of the import - there was a wizard for DTS imports in VS200-2005, there's bound to be one in the later versions.


如果我理解正确你可以在excel中使用通用数据类型
if i understood it correctly you can use general datatype in excel


这篇关于在sql server中用于存储文本aswellas编号的数据类型的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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