如何在sql server中使用storedprocedure从字符串中获取子字符串

编程入门 行业动态 更新时间:2024-10-22 07:31:17
本文介绍了如何在sql server中使用storedprocedure从字符串中获取子字符串的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我有这样的表数据:

I have table data like this:

sno component subcomponent Irnumber 1 1 c1 to c100 001 2 1 c200 to c444 002 3 1 c450,c451,c455 003

在文本框中,用户输入c50 ....我需要检索第一条记录

here in the text box user enters c50....i need to retrieve first record

1 1 c1 to c100 001

请帮助我。

please help me.

推荐答案

不要那样存储。 SQL不擅长字符串操作,你需要找到两个数字,提取它们,验证它们,将它们转换为整数,然后比较它们。 相反,更改数据库使用两个整数列(可能还有一个NVARCHAR列作为前缀)并使用BETWEEN: Don't store it like that. SQL is not good at string manipulations, and you need to find two numbers, extract them, validate them, convert them to an integer, and then compare them. Instead, change your database to use two integer columns (and possibly an NVARCHAR column for the prefix) and use BETWEEN: sno component prefix subcomponentStart subcomponentEnd Irnumber 1 1 C 1 100 001

SELECT * FROM MyTable WHERE Prefix='C' AND ValueFromUser BETWEEN subcomponentStart AND subcomponentEnd

更多推荐

如何在sql server中使用storedprocedure从字符串中获取子字符串

本文发布于:2023-10-27 00:02:11,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1531727.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:字符串   如何在   server   sql   storedprocedure

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!