计算当前日期的字符串 [英] Count the String for the current date
问题描述
我在表格中有一个new,complete,inprogress,deleted的特定值。
当有关于条目的条目时我需要计算每个字符串当前日期。
任何人都可以帮助我..
请注意,这是针对MS SQL Server的 - 您没有指定哪个数据库。
状态是您的字段,包含新的,完整的等...
< pre lang =SQL> DECLARE @ dt datetime
SET @ dt = GetDate()
SELECT 状态,COUNT(*) FROM your_table
WHERE your_date_field = CONVERT ( datetime , @dt , 104 )
GROUP BY status
请注意,状态表最好是
PK代码值
----------------------------
10 new new
20 compl完成
30 inpr正在进行中
如果我需要枚举名称或其他名称,我会使用代码字段没有用户需要看到它的任务......而值则是向用户展示的东西。编号用于组合框/单选按钮列表,排序等...
优点是
a)您可以按整数轻松排序首要的关键。
b)如果有人有了新想法,你可以轻松添加中间状态。
c)您不必完全输入单词并担心区分大小写的比较。
d)您可以向用户显示您想要的任何文本,而无需更改单行代码。
缺点是您必须链接表格如果您需要名称(或编写返回任何给定PK名称的函数) - 这就是我所做的:)
string strQury = < span class =code-string> 从sqsh.view_smartopd中选择count(*),其中servicedisplayname =' + strDocName + '和tokendate =' + dt + '和value ='new';;
countNew = rdr.GetInt32( count(*)跨度>);
txtTotalPatient。文字 = countNew.ToString()
I have a certain values as "new , complete , inprogress , deleted" in table.
I need to count each string when there is a entry with respect to the current date.
Could any one help me..
Note that this is for MS SQL Server - you didn't specify which database.
status is your field that contains new, complete, etc...
DECLARE @dt datetime SET @dt = GetDate() SELECT status, COUNT(*) FROM your_table WHERE your_date_field = CONVERT(datetime, @dt, 104) GROUP BY status
Note that it would be better to have status table something like
PK code value ---------------------------- 10 new New 20 compl Complete 30 inpr In progress
I use code field if I need Enum names or some other no-user-needs-to-see-it task...while value is something to show the user. Number is used for combobox /radio button lists, sorting, etc...
Advantages are
a) you can easily sort by your integer primary key.
b) You can easily add in-between statuses if someone gets new idea.
c) You're not bound to exactly typing the word and worrying about case sensitive comparisons.
d) You can show your user whatever text you want without changing single line of code.
Disadvantage is that you have to link the table if you need the name (or write the function that returns the name for any given PK) - this is what I did :)
string strQury = "select count(*) from sqsh.view_smartopd where servicedisplayname = '" + strDocName + "' and tokendate = '" + dt + "' and value = 'new';"; countNew = rdr.GetInt32("count(*)"); txtTotalPatient.Text = countNew.ToString()
这篇关于计算当前日期的字符串的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!