我有一个带有一堆数字的字符串,但它在字符串中心的某个位置包含一个字母。该字母可以是“A”或“B”。我试图用 Charindex() 函数找出这封信的位置。但是,当您有两个搜索参数时,它不起作用:
select charindex('[A,B]','190118A3700000')
Run Code Online (Sandbox Code Playgroud)
我尝试使用范围和通配符,但没有成功。所以我想要的是将这两个单独的查询合并为一个:
select charindex('A','190118A3700000')
select charindex('B','190118A3700000')
Run Code Online (Sandbox Code Playgroud)
有人知道如何做到这一点吗?
谢谢你!!!
我真的很想学习和理解如何使用游标方法连接字符串。
这是我的表:
declare @t table (id int, city varchar(15))
insert into @t values
(1, 'Rome')
,(1, 'Dallas')
,(2, 'Berlin')
,(2, 'Rome')
,(2, 'Tokyo')
,(3, 'Miami')
,(3, 'Bergen')
Run Code Online (Sandbox Code Playgroud)
我正在尝试创建一个表,其中包含按字母顺序排序的一行中每个 ID 的所有城市。
ID City
1 Dallas, Rome
2 Berlin, Rome, Tokyo
3 Bergen, Miami
Run Code Online (Sandbox Code Playgroud)
到目前为止,这是我的代码,但它不起作用,如果有人能引导我完成每一步,我会非常高兴并渴望学习它!
set nocount on
declare @tid int
declare @tcity varchar(15)
declare CityCursor CURSOR FOR
select * from @t
order by id, city
open CityCursor
fetch next from CityCursor into @tid, @tcity
while ( @@FETCH_STATUS = 0)
begin
if …Run Code Online (Sandbox Code Playgroud) 我需要对表进行排序,我需要在底部显示包含Null的行.每当我运行以下查询
select * from t1
order by status, date;
Run Code Online (Sandbox Code Playgroud)
Null出现在我不想要的第一行:
+--------+------------+--+
| Status | Date | |
+--------+------------+--+
| 1 | NULL | |
| 1 | 2011-12-01 | |
| 1 | 2011-12-21 | |
| 2 | NULL | |
| 2 | 2005-09-02 | |
| 3 | 2000-08-07 | |
| | | |
+--------+------------+--+
Run Code Online (Sandbox Code Playgroud)
这就是我需要的:
+--------+------------+--+
| Status | Date | |
+--------+------------+--+
| 1 | 2011-12-01 | |
| 1 | 2011-12-21 | | …Run Code Online (Sandbox Code Playgroud) 我试图在 CLI 中找出我在 Linux Ubuntu 中知道的命令,但我需要在 Microsoft 中应用它。
此外,我试图在具有特定名称的文件夹中查找所有文件。特别是,我尝试查找名称中包含术语“测试”的所有文件。这是我在 Linux 中知道的命令:
find \home\user\data -name '*test*'
Run Code Online (Sandbox Code Playgroud)
有谁知道 Windows 命令行中的等价物?
我想用两列作为乘法因子来构建一个总和.请参阅示例数据:
+------------+-------------+
| Amount | Rate |
+------------+-------------+
| 8 | 4.1 |
| 3 | 2.5 |
| 7 | 5.3 |
+------------+-------------+
Run Code Online (Sandbox Code Playgroud)
所以我有这个表,我正在努力与乘法的这些结果的总量.我可以建立第三列并计算(8*4.1)+(3*2.5)+(7*5.3)
但我想直接从两列中完成.到目前为止我用过
sum(amount) * sum(rate)
Run Code Online (Sandbox Code Playgroud)
但它没有给我正确的结果.谁能帮助我,告诉我正确的配方是什么?
非常感谢你!
sql-server ×4
sql ×2
t-sql ×2
charindex ×1
command-line ×1
cursor ×1
null ×1
powershell ×1
sql-order-by ×1
string ×1
sum ×1
windows ×1