如何在sql server中触发时间格式转换的触发器? [英] How to fire a trigger for time format conversion in sql server?

查看:97
本文介绍了如何在sql server中触发时间格式转换的触发器?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在sql server中创建了一个数据类型为time的表。当我向该表插入任何值时,它显示为hh:mm:ss .----- format。例如 - 如果我插入09:30它将会像09:30:00.000 -----

i想要在触发器的帮助下09:30:00.000到09:30 AM / PM转换即,当我插入任何值时,它应转换为(varchar / 09:30 AM / PM)格式。

I have created a table in sql server with the datatype "time". when i insert any value to this table, it shows like hh:mm:ss.----- format. For Example- if i insert 09:30 it will come like 09:30:00.000-----
i want to convert 09:30:00.000 to 09:30AM/PM with the help of trigger i.e. when i insert any value it should convert in (varchar/09:30AM/PM) format.

推荐答案

SQL不存储格式化的时间(和日期)值,但是二进制。您看到的格式是用于显示值的客户端功能的一部分......因此,如果要以特定格式在应用程序中显示时间值,可以使用 DateTime.ToString [ ^ ]方法...

您提到的样本你可以使用字符串hh:mm tt......

有关格式字符串的更多信息:

https://msdn.microsoft.com/en-us/library/az4se3k1(v=vs.110).aspx [ ^ ]

https://msdn.microsoft.com /en-us/library/8kb3ddd4(v=vs.110).aspx [ ^ ]
SQL does not store time (and date) values formatted, but in binary. The format you see is part of the functionality of the client you use to display the value...So if you want to display a time value in your application in a specific format you may use DateTime.ToString[^] method...
For the sample you mentioned you may use the string "hh:mm tt"...
More info about format strings:
https://msdn.microsoft.com/en-us/library/az4se3k1(v=vs.110).aspx[^]
https://msdn.microsoft.com/en-us/library/8kb3ddd4(v=vs.110).aspx[^]


这篇关于如何在sql server中触发时间格式转换的触发器?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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