我有一个C#语句:
Date.Now.ToString("yyyy_MM_yy_HH_mm_ss_ms")
Run Code Online (Sandbox Code Playgroud)
现在,我需要在SQL Server 2008 R2中使用相同的功能.我知道我可以GETDATE用于当前日期.但是无法获得这种格式.
我在我的SQL Server中有一个存储过程,它以这些行代码开头:
CREATE PROCEDURE [dbo].[SP_Notify]
-- Add the parameters for the stored procedure here
@UserName nvarchar(50),
@lastDate datetime
AS
BEGIN
-- my code...
Run Code Online (Sandbox Code Playgroud)
我尝试使用以下代码调用存储过程:
DECLARE @data datetime
DECLARE @Username nvarchar(50)
SET @Username = CAST('myUserName' AS nvarchar(50))
SET @data = GetDate()
SP_Notify @Username , @data
Run Code Online (Sandbox Code Playgroud)
但这会导致此错误:
消息102,级别15,状态1,行
10'SP_Notify'附近的语法错误.
我想显示表中col1重复的所有行.
+------+------+------+
| col1 | col2 | col3 |
+------+------+------+
| 1 | 0 | 0 |
| 1 | 1 | 1 |
| 2 | 0 | 0 |
| 3 | 0 | 0 |
| 3 | 1 | 1 |
| 4 | 0 | 0 |
+------+------+------+
Run Code Online (Sandbox Code Playgroud)
结果应该是:
+------+------+------+
| col1 | col2 | col3 |
+------+------+------+
| 1 | 0 | 0 |
| 1 | 1 | 1 |
| 3 | …Run Code Online (Sandbox Code Playgroud) Select Name from tblAnimal where Id=1
Run Code Online (Sandbox Code Playgroud)
退货:我的宠物
Select Id from tblAnimal where Name='My Pet' --I copy/pasted this value in SSMS!
Run Code Online (Sandbox Code Playgroud)
返回空的变更集(为什么?)
经过一番研究后我发现它可以是Char(10)和Char(13).所以,我想,当我复制My Pet的粘贴时,会自动将Char(10)转换为Space for Windows环境吗?
因为这:
Select id from tblAnimal where Name like '%My%'
Run Code Online (Sandbox Code Playgroud)
返回1而
select id from Animal where Name like '%My %'
Run Code Online (Sandbox Code Playgroud)
没有回报.
问题.
1.为什么会这样?
2.如何解决这个问题(生产数据库,数百万条记录)
3.如何防止这种情况发生?
CI有一个简单的方法,我可以找到第一次出现在列中具有特定值的行?例如,假设我有这两个表
Alphabet
A
B
C
D
Alphabet Usage
A Apple
B Bat
D Dog
A Amateur
A Arsenal
C Cat
B Ball
D Drum
Run Code Online (Sandbox Code Playgroud)
在第一个表中选择所有内容以及在第二个表中首次使用它的简单方法是什么?
预期产出:
Alphabet Usage
A Apple
B Bat
C Cat
D Dog
Run Code Online (Sandbox Code Playgroud) 我正在使用SQL Server 2008 R2和SQL Server 2012.
在运行SSMS时,如何指定是否必须使用运行提示打开SSMS 2008 R2或SSMS 2012?让我们说现在我必须使用RUN提示符打开SSMS 2012.
有人可以帮助我如何打开它?提前致谢.
我意识到这是一个相对基本的问题,但是日期时间总是搞砸了我,我想确保我正确地做到这一点(这个审计将被提升为老板).使用sql server 2008 r2.下面的一些sudo代码可以满足我的需求
我应该提到transactionDate目前是一个日期时间.这会改变一切吗?
DELCARE
@today datetime,
@tomorrow datetime
SET @today = --CODE TO GET THE DATE FOR TODAY
SET @tomorrow = --CODE TO GET THE DATE FOR TOMORROW
SELECT *
FROM table
WHERE custID = '788'
AND status = 'Cancelled'
AND transactionDate --IS ONLY TODAY AND NOT TOMORROW OR ANY DAY AFTER
Run Code Online (Sandbox Code Playgroud) 当我在SQL Server 2008中获得行数时遇到问题,因为我的代码使用MySQL可以正常运行,但在SQL Server中却不能。
$sql = "SELECT TOP 1 U.Id , U.Name, U.Profile, P.Name NameProfile
FROM sa_users U
INNER JOIN sa_profiles P ON P.Id = U.Profile
WHERE User = :user AND Pass = :pass";
$result = $this->dbConnect->prepare($sql) or die ($sql);
$result->bindParam(':user',$this->data['username'],PDO::PARAM_STR);
$result->bindParam(':pass',$this->data['password'],PDO::PARAM_STR);
if (!$result->execute()) {
return false;
}
$numrows = $result->rowCount();
$jsonLogin = array();
var_dump($numrows);
if($numrows > 0) {
while ($row = $result->fetch(PDO::FETCH_ASSOC)) {
$jsonLogin = array(
'name' => $row['Name'],
'id' => $row['Id'],
'profile' => $row['Profile'],
'n_profile' => $row['NameProfile']
); …Run Code Online (Sandbox Code Playgroud) 我想在将新成员插入数据库后刷新DataGridView.我在主窗体上创建了一个方法,该方法发生在mainform_load上.从另一种形式(addmember),在我点击SaveMemberButton后,我正在调用该方法来刷新datagridview,但它不会发生.
这是我在主窗体上的代码:
private void MainForm_Load(object sender, EventArgs e)
{
//ShowLoginForm();
ListMembers();
}
public void ListMembers()
{
MembersDataGridView.Columns.Clear();
MembersDataGridView.DataSource = Connection.ListMembers();
MembersDataGridView.ClearSelection();
}
Run Code Online (Sandbox Code Playgroud)
这是我在另一种形式上的代码:
private MainForm mainForm = new MainForm();
private void SaveMemberButton_Click(object sender, EventArgs e)
{
try
{
if (IsValid())
{
var member = new Member
{
Name = AddNewNameTextBox.Text,
Surname = AddNewSurnameTextBox.Text,
EntryDate = DateTime.ParseExact(AddNewEntryDateTextBox.Text, "dd.MM.yyyy", CultureInfo.InvariantCulture),
};
Connection.InsertMember(member);
MessageBox.Show("Member registration successful!");
}
mainForm.ListMembers();
this.Close();
}
catch (Exception exception)
{
MessageBox.Show(exception.Message);
}
}
Run Code Online (Sandbox Code Playgroud)
这是从数据库获取数据的代码:
public List<Member> ListMembers()
{
List<Member> …Run Code Online (Sandbox Code Playgroud) 我一直试图让这个权利超过2小时,所以任何帮助都非常感谢
public void setAppointment(int studentID, DateTime appt)
{
connection.Open();
string sqlStatement3 = "UPDATE dbo.students SET appointmentDate = '" + appt.Date.ToString("yyyy-MM-dd HH:mm:ss") + "' WHERE ID = " + studentID + ";";
OleDbCommand updateCommand = new OleDbCommand(sqlStatement3, connection);
updateCommand.ExecuteNonQuery();
connection.Close();
}
Run Code Online (Sandbox Code Playgroud)
所以基本上做的是将日期时间插入到sql server表中,保持月和日的相同格式,以避免区域设置妨碍.
唯一的问题是时间仍然是00:00:00.即使我调试代码时,'appt'显示28/06/2013 09:30:00