如何在sql server 2008中使用for string [英] how to use between for string in sql server 2008

查看:68
本文介绍了如何在sql server 2008中使用for string的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好



这里我的问题是我想找到字符串,下面我提到薪水月份列。在这里,我想找到字符串

Hi All

here my problem is i want to find strings , below i mention the salary month column. here i want to find string

AUGUST-2015 from DECEMBER-2015

,所以我想要哪个月的列表在这两个月之间在sql server中可用怎么做?...



, so i want list of which month available between this two month in sql server how to do that ?...

Salary Month

DECEMBER-2015
NOVEMBER-2015
DECEMBER-2015
DECEMBER-2015
OCTOBER-2015
AUGUST-2015
SEPTEMBER-2015





谢谢



thanks

推荐答案

如果您想对数据做任何严肃的事情,您必须存储它格式正确:并且VARCHAR或NVARCHAR仅适用于实际的字符串值,例如名称,地址,描述和电话号码。

如果你想对一个值做任何形式的数学运算,它需要存储为数字列,类似日期应该在DATE或DATETIME列中。还有别的,你开始给自己带来真正的问题 - 以后它们会引起很大的痛苦,因为字符串在某些时候总会保持无效的值。也许不是今天你的代码,但是在三个月的时间里,其他人已经攻击了一个额外的功能......并猜猜谁能解决它? :笑:



如果你从两个表中使用它,那么改变两者:这不是一个很好的存储信息的理由。而且它在存储上的空间效率也要高得多!

字符串比较总是在逐个字符的基础上进行,第一个不同的字符控制着整个比较 - 所以要使用你的数据是,你需要将它转换为日期 - 所以改变你的数据库,一切都将开始正常工作。将它留作字符串会让你感到非常悲伤,而不仅仅是因为这个问题。
If you want to do anything serious with data, you have to store it in the right format: and VARCHAR or NVARCHAR is only appropriate for actual string values, such as names, addresses, descriptions, and telephone numbers.
If you want to do any form of maths on a value, it needs to be stored as a numeric column, and similarly dates should be in DATE or DATETIME columns. Anything else, and you start to give yourself real problems - and they can cause major pain later on, because strings will always get to hold invalid values at some point. Maybe not from your code today, but in three months time when someone else has hacked in an extra feature...and guess who gets to sort it out? :laugh:

If you are using this from two tables, then change both: that isn't a good reason for storing information badly. And it's a lot more space efficient on storage as well!
String comparisons are always on a character by character basis, with the first different character controlling the whole comparison - so to use your data is it is, you would need to convert it to dates anyway - so change your DB and everything will just start to work properly. Leaving it as strings is going to cause you a lot of grief, and not just for this problem.


我真的不推荐这个,但是你必须这样做。

然后一种方法是创建一个像



ID表月份名称

1月1日

2 FEBRUARY

...

12月12日



选择这个月份名='8月'或monthname ='DECEMBER'

为您提供ID-s,然后您可以使用ID-s在相同的表格中选择ID-s在您的ID-s之间进行选择。

并为您提供您正在寻找的月份名称,并将其用于您需要的选项。



您还需要一些字符串处理来删除/追加年份但是我把它作为一种练习就可以了。
I really don´t recommend this but if you must do it this way.
Then one way is to create a table like

ID Monthname
1 JANUARY
2 FEBRUARY
...
12 DECEMBER

A select on this with monthname = 'AUGUST' or monthname = 'DECEMBER'
gives you ID-s that you can then use to do select on the same table with ID-s between your ID-s in the previus select.
and give you the month names that you are looking for and use them for the select you need.

You also need some string handling to remove/append years but I leave that out as a exercise on it´s own.


这篇关于如何在sql server 2008中使用for string的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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