我有一个 sql 表,如下所示:
srno | passportnumber|flightnumber
Null | ABC123 |AI-2000
Null | ab3333 |AI-2011
Null | ab565235 |AI-2562
Null | ABC123 |AI-2025
Null | ABC123 |AI-5623
Null | XYZ12334 |AI-5625
Run Code Online (Sandbox Code Playgroud)
我需要一个查询来按护照号码对它们进行排序,以便重复的护照号码 rpw 彼此相邻,然后我想更新表格以插入序列号。结果应该是这样的:
1 | ABC123 |AI-2000
2 | ABC123 |AI-2025
3 | ABC123 |AI-5623
4 | ab3333 |AI-2011
5 | ab565235 |AI-2562
6 | XYZ12334 |AI-5625
Run Code Online (Sandbox Code Playgroud) 在 SQL Server 中,我使用查询更新表,而不添加 where 条件。现在我想要表中所有以前的记录。我怎样才能取回所有行。该查询直接执行,没有使用任何事务。
如何从DateTimeC# 中的结构仅将日期的时间部分插入 Sql Server 。我想以HH:mm tt(HH:MM AM/PM)格式保存时间
我尝试了以下数据类型:
timetimestampdatetimetime(7)示例查询:
SqlCommand cmd = new SqlCommand("insert into Reminder values ('" + txttitle.Text + "','" + txtdate.Text + "','" + txttime.Text + "','" + Txtmail.Text + "')", conn);
cmd.ExecuteNonQuery();
Run Code Online (Sandbox Code Playgroud) 我已经阅读并尝试使用一系列间隙和孤岛检测的标准方法,但没有成功,因为我需要能够忽略任何小于 30 分钟的间隙。由于性能问题,我无法使用游标。
每当有至少 30 分钟的间隙时,我都需要一个包含开始和结束的新行。如果没有至少 30 的间隙,结果将是包含时间戳最小值和最大值的一行。如果有 1 个间隙至少为 30,则将有 2 行 - 从系列的开头到间隙以及从间隙到结束。如果有更多间隙,我们会获取间隙之间每个间隔的行,等等。
输入:
timestamp
2015-07-15 15:01:21
2015-07-15 15:17:44
2015-07-15 15:17:53
2015-07-15 15:18:34
2015-07-15 15:21:41
2015-07-15 15:58:12
2015-07-15 15:59:12
2015-07-15 16:05:12
2015-07-15 17:02:12
Run Code Online (Sandbox Code Playgroud)
期望的输出:
from | to
2015-07-15 15:01:21 | 2015-07-15 15:21:41
2015-07-15 15:58:12 | 2015-07-15 16:05:12
2015-07-15 17:02:12 | 2015-07-15 17:02:12
Run Code Online (Sandbox Code Playgroud) 我有一个参数传入用户输入,然后该参数进入查询以进行通配符搜索。
如同:
DECLARE @myVariableContainingUserInput VARCHAR(50) = 'part of string';
DECLARE @myTable TABLE (column1 varchar(200));
INSERT INTO @myTable(column1)
VALUES ('This is the whole string that contains part of string the user is looking for')
SELECT column1
FROM @myTable
WHERE column1 LIKE '%' + @myVariableContainingUserInput + '%'
Run Code Online (Sandbox Code Playgroud)
在这种情况下,他们得到一排。
然而有时数据看起来像这样:
INSERT INTO @myTable(column1)
VALUES ('This is the whole string that contains [part] of string the user is looking for')
Run Code Online (Sandbox Code Playgroud)
用户有时可能会搜索
SET @myVariableContainingUserInput = '[part';
Run Code Online (Sandbox Code Playgroud)
他们希望找到一行包含“这是包含用户正在查找的字符串的[部分]的整个字符串”。并不是因为 [ 是一个特殊字符。
我知道我可以通过使用[[]或例如添加 a\并使用 …
我的一个SQL Server中有一个奇怪的问题.我有一个Identity刀片上的一个seq id栏,它在那里的一些时间点increased由2数字代替1.我的身份增量设置不是两个.Identity列可能有什么问题?
我有这样的程序:
create proc SearchField (@YearDate)
Run Code Online (Sandbox Code Playgroud)
如果我只放一年,我怎么能把这个@YearDate作为整整一年?所以如果我把'2013'它将从2013年1月1日至2013年12月31日进行搜索.
我试图插入我的表Add_Product,但它不工作.它没有进入数据库,既没有显示任何错误这是我的连接类:
public static class ConnectionClass
{
private static SqlConnection con;
private static SqlCommand cmd;
static ConnectionClass()
{
string conString = ConfigurationManager.ConnectionStrings["DBCS"].ConnectionString;
con = new SqlConnection(conString);
}
public static void AddProduct(Product product)
{
cmd = new SqlCommand("insert into Add_Product (Party, Product_Name, Price, Quantity,Type,Details,Date) values (@Party, @Product_Name, @Price,Quantity,@Type,@Details, @Date,)", con);
cmd.Parameters.AddWithValue("@Party", product.Party);
cmd.Parameters.AddWithValue("@Product_Name", product.Product_Name);
cmd.Parameters.AddWithValue("@Price", product.Price);
cmd.Parameters.AddWithValue("@Quantity", product.Quantity);
cmd.Parameters.AddWithValue("@Type", product.Type);
cmd.Parameters.AddWithValue("@Details", product.Quantity);
cmd.Parameters.AddWithValue("@Date", product.Date);
try
{
con.Open();
cmd.ExecuteNonQuery();
}
finally
{
con.Close();
cmd.Parameters.Clear();
}
}
}
}
Run Code Online (Sandbox Code Playgroud)
这是Product类构造函数:
public Product(string Party, string …Run Code Online (Sandbox Code Playgroud) 首先,我是SQL新手.下面是示例(对于table1和table2,我创建了一个SNO作为主键,这也是标识列)
表1:
PID PNAME PartID
--- ----- ------
0 Length 1
1 Breadth 1
2 Height 1
0 Area 2
1 Volume 2
Run Code Online (Sandbox Code Playgroud)
表2:
SampleID PID Pvalue PartID ModifiedDate Operator
-------- --- ------ ------ ------------ --------
0 0 10 1 10-Mar-14 Test
0 1 10 1 10-Mar-14 Test
0 2 Fail 1 10-Mar-14 Test
1 0 20 1 12-Mar-14 Test
1 1 Fail 1 12-Mar-14 Test
1 2 Fail 1 12-Mar-14 Test …Run Code Online (Sandbox Code Playgroud) public bool location()
{
string OUI = "OUI";
SqlConnection con = new SqlConnection(@"Data Source=WIN-218NC1F1FE2\SQLEXPRESS;Initial Catalog=projet;Integrated Security=True");
con.Open();
SqlCommand cmd = new SqlCommand("select max(id_reservation) from reservation");
cmd.Connection = con;
Int32 maxId = (Int32)cmd.ExecuteScalar();
string v = Convert.ToString(maxId);
//correct
SqlCommand q = new SqlCommand("insert into reservation(location) values('" + OUI + "') where id_reservation ='"+ maxId + "'", con);
SqlDataReader da = q.ExecuteReader();
return true ;
}
Run Code Online (Sandbox Code Playgroud)
问题在命令中:关键字'where'附近的语法不正确.救命 !!!
sql-server-2008 ×10
sql ×6
sql-server ×6
c# ×3
t-sql ×3
database ×1
datetime ×1
pivot ×1
sql-insert ×1