且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

使用 Charindex 获取字符左侧的数据

更新时间:2023-11-09 23:34:34

这不行吗?

left(appts.subject, charindex('-', appts.subject) - 1)

如果这失败是因为并非所有科目都有 -,那么:

If this fails because not all subjects have a -, then:

left(appts.subject, charindex('-', appts.subject + '-') - 1)

以上在 Sybase 中有效.在 Advantage SQL 中,我认为您需要 location:

The above works in Sybase. In Advantage SQL, I think you need location:

left(appts.subject, locate('-', appts.subject) - 1)