假设我有一个包含两列的表格:
ID, FullName
Run Code Online (Sandbox Code Playgroud)
我在其中有以下记录:
John Bob Smith
John Bobby Smith
Run Code Online (Sandbox Code Playgroud)
我的问题是:
我想只返回包含匹配单词"Bob"的行,并且我不想返回任何包含类似"Bobby"字样的行
当我搜索时使用:
Select *
From Table1
Where FullName like '%bob%'
Run Code Online (Sandbox Code Playgroud)
我得到了两行错了.
Select *
From Table1
Where FullName = 'Bob'
Run Code Online (Sandbox Code Playgroud)
这根本不返回任何行.
Select *
From Table1
Where FullName like 'Bob'
Run Code Online (Sandbox Code Playgroud)
这也不会返回任何行.
我尝试使用不同的通配符,但没有任何作用,我也试过了CHARINDEX,PATINDEX但他们也没有返回所需的结果.
有什么建议?
谢谢.
我需要一些帮助SQL查询.我有一个列的值存储为逗号分隔值.
我需要编写一个查询,查找列中每个值中的第3个分隔项.
这可以在Select语句中执行此操作吗?例如:ColumnValue:josh,Reg01,False,a0-t0,22/09/2010
所以我需要False从上面的字符串中获取第3个值(即).
我的一个包体中有以下动态SQL
OPEN ccur for
'select c.category
from test_category c
where c.deptid='||PI_N_Dept ||
' and c.category not in ('|| sExcludeCategories ||')';
Run Code Online (Sandbox Code Playgroud)
sExcludeCategories将包含一组用逗号分隔的整数.我想消除这种动态SQL语句.有没有聪明的方法来实现这一目标?
我想知道是否有人可以帮助我.
我需要一个tsql函数来拆分给定的值,例如:
1) 00 Not specified
3) 01-05 Global WM&BB | Operations
2) 02-05-01 Global WM&BB | Operations | Operations n/a
Run Code Online (Sandbox Code Playgroud)
我需要得到这样的结果:
cat1 cat1descr cat2 cat2descr cat3 cat3descr
----------------------------------------------------------------
00 Not especified null null null null
01 Global WM&BB 05 Operations null null
01 Global WM&BB 05 Operations 01 Operations n/a
Run Code Online (Sandbox Code Playgroud)
结果总是有6列
选择funcX('00未指定');
cat1 cat1descr cat2 cat2descr cat3 cat3descr
----------------------------------------------------------------
00 Not especified null null null null
Run Code Online (Sandbox Code Playgroud) 我想使用SQL Server 2005执行以下操作.
创建一个以varchar()逗号","分隔的参数的存储过程
拆分/分解varchar()参数并将值插入临时表中
将执行以下操作的内容:
INSERT INTO #temp_table SPLIT('john,peter,sally',',');
SELECT * FROM #temp_table;
Run Code Online (Sandbox Code Playgroud)
是否有执行拆分的函数或存储过程?
如果是这样,它是如何工作的?
谢谢
sql-server split stored-procedures sql-server-2005 temp-tables
我full_location_id在表中有一个column(),其中包含一个由' - '分隔的字符串,我需要在视图(Test_SplitColumn)中将其拆分为4列.并非每个记录都full_location_id包含相同长度的ID.有些可能有像A1-BF-35-B1这样的ids,而有些可能只有AR-B3.我不确定这样做的最佳方式.我能够检索第一列,但到目前为止,不是其他列.
CREATE VIEW [dbo].[Test_SplitColumn]
AS
select p.name, location.aisle_id, location.full_location_id, SUBSTRING(location.full_location_id, 0,charindex('-', location.full_location_id )) as Aisle,
SUBSTRING(location.full_location_id, charindex('-', location.full_location_id ) + 1, charindex('-', location.full_location_id, LEN(SUBSTRING(location.full_location_id, 0,charindex('-', location.full_location_id ))) )) as ShelvingUnit
from location
inner join product p on p.id = location.product_id
GO
Run Code Online (Sandbox Code Playgroud)
任何帮助或指导将不胜感激.
如果我有一个字符串,其中包含用"/"字符(xxx ... xxx/xxx/xxxx)分隔的其他字符串,我怎样才能获得t-sql的最后一个和最后一个(最后一个)部分?它应该是charindex()和right()的某种组合.
如何在SQL Server中拆分字符串.
例:
输入字符串: stack over flow
结果:
stack
over
flow
Run Code Online (Sandbox Code Playgroud) 我想知道如何(如果可能的话)颠倒从TSQL字符串(varchar)返回的单词的顺序.
我知道TSQL REVERSE函数,但也反转了单词中的字母,例如:
输入> We want to tell you we all love StackOverflow
输出>wolfrevOkcatS evol lla ew uoy llet ot tnaw eW
我想在TSQL中实际实现以下功能:
输入> We want to tell you we all love StackOverflow
输出>Stackoverflow love all we you tell to want We
我在任何地方找到的唯一一个稍微类似的问题是这个,但是包括拆分逗号分隔的字符串,我不需要这样做.
我确信有一种方法可以实现上述目标,即使它是自定义函数或SQL-CLR函数,任何帮助都将非常感激.
编辑:
我设法使用以下方法拆分我的字符串:
-- Create a space delimited string for testing
declare @str varchar(max)
select @str = 'We want to tell you we all love StackOverflow'
-- XML tag the …Run Code Online (Sandbox Code Playgroud) 更新: 有人将此问题标记为“我如何分割字符串,以便可以访问项目x”的重复 项。但这是不同的,我的问题是关于Sybase SQL Anywhere,另一个是关于MS SQL Server。这是两个不同的SQL引擎,即使它们具有相同的来源,也具有不同的语法。因此它不是重复的。我首先在描述和标签中写到了关于Sybase SQL Anywhere的全部内容。
我有田野 id_list='1234,23,56,576,1231,567,122,87876,57553,1216'
我想用它来搜索IN该字段:
SELECT *
FROM table1
WHERE id IN (id_list)
Run Code Online (Sandbox Code Playgroud)
id 是 integer
id_list 是 varchar/text
但是以这种方式行不通,因此我需要以某种方式拆分id_list为选择查询。
我应该在这里使用什么解决方案?我正在使用T-SQL Sybase ASA 9数据库(SQL Anywhere)。
我看到的方式是,通过while循环创建自己的函数,并基于分隔符位置搜索拆分每个元素,然后将元素插入到临时表中,该函数将作为结果返回。
sql ×6
t-sql ×6
sql-server ×5
split ×3
csv ×1
oracle ×1
parsing ×1
plsql ×1
search ×1
sqlanywhere ×1
sqlclr ×1
sybase ×1
temp-tables ×1