无论如何从cmd.exe运行存储过程?
ps
我知道如何创建exec文件c#并运行它.
我问的是没有任何代码:
只是我和cmd.exe.
我和cmd.exe:意思是我不想写任何代码.内部SQL Server帮助exe文件的sql很好!
抱歉没有澄清这个!
我正在开发一个ATM软件作为家庭作业,在其中我想知道今天要处理的交易总额,为此,我编写了以下代码
public decimal getDayTransaction(int accountid, string date, string transactiontype)
{
decimal totalamount = 0;
int i = 0;
string connectionString =
"Persist Security Info=False;User ID=sa; Password=123;Initial Catalog=ATMSoftware;Server=Bilal-PC";
try
{
using (SqlConnection connection =
new SqlConnection(connectionString))
{
SqlCommand command = new SqlCommand(
"Select Amount From [Transaction] where AccountID = "
+ accountid + " AND CurrDate ='" + date
+ "' AND TransactionType = '"
+ transactiontype + "';", connection);
connection.Open();
SqlDataReader dr = command.ExecuteReader();
while (dr.Read())
{
totalamount += Convert.ToDecimal(dr.GetString(i)); …Run Code Online (Sandbox Code Playgroud) 目前,我们有一个存储过程,通过执行以下操作,从其原始模式中的表返回数据:
WITH CTE AS
(
-- Start CTE off by selecting the id that was provided to stored procedure.
SELECT *
FROM [dbo].[TestTable]
WHERE [Id] = 1
-- Recursively add tasks that are children of records already found in previous iterations.
UNION ALL
SELECT t.*
FROM [dbo].[TestTable] as t
INNER JOIN CTE as tcte
ON t.[ParentId] = tcte.[Id]
)
SELECT *
FROM CTE
Run Code Online (Sandbox Code Playgroud)
这很好,因为无论表架构如何更改,只要有[Id]和[ParentId]列,我就不必更新此存储过程.我想做类似的事情,但也能够动态指定递归的深度.我看到这样做的唯一方法是添加一个Level/Depth标识符,如下所示:
WITH CTE AS
(
-- Start CTE off by selecting the task that was provided to …Run Code Online (Sandbox Code Playgroud) 有一个简单的select * from myTable查询和一个名为的列Fruits
Fruits 有以下数据:
Apple
Pear
Peach
Plum
Grape
Run Code Online (Sandbox Code Playgroud)
我总是首先要葡萄,然后依次是剩下的葡萄,结果就是这样
Grape
Apple
Peach
Pear
Plum
Run Code Online (Sandbox Code Playgroud)
一如既往地感谢您的帮助!
我一直在SQL Server 2005数据库中使用Narayana Vyas Kondreddi的优秀存储过程sp_generate_inserts http://vyaskn.tripod.com/code/generate_inserts.txt.
但是在转移到SQL Server 2008后,我得到了奇怪的结果,其中在UNIQUEIDENTIFIER值之后插入了一个长空格:
INSERT INTO [BannerGroups]([Id], [DescriptionText], [Width], [Height])
VALUES('BFCD0173-9432-47D1-84DF-8AB3FB40BF76 ', 'Example', 145, NULL)
Run Code Online (Sandbox Code Playgroud)
有人知道怎么修这个东西吗?
sql-server stored-procedures sql-server-2005 sql-server-2008

嗨,
我有如上所示的"Table1",上面有一些记录,列名是Id,Name和[Entry Date].列Id是主键,我使用的是SQL Server 2005.
我想编写一个每5条记录返回一次信息的查询,例如我的查询将返回:

正如您在最终结果中看到的那样,只选择了每5条记录的记录,我该如何做到这一点?
谢谢
我需要在表中插入值.但我的条件是我需要Min(date)从另一个表中选择,这个值应该插入到另一个表中.
我的查询
Insert into tempTable values
('Value1','Value2','Value3',(select min(val_dt) from anotherTable),'Y',getdate())
Run Code Online (Sandbox Code Playgroud)
如果我使用此查询,我将面临错误.
指导我如何在插入查询中使用select查询.
我想根据表动态生成变量声明.我的意思是,我想声明一个表的变量,每个变量必须与它的列相同类型我正在做类似的事情,但结果只有在类型不是int时才有效
Select 'Declare @Doc' + COLUMN_NAME + ' '+DATA_TYPE+case(CHARACTER_MAXIMUM_LENGTH) when Null then ' ' else '(' +convert(varchar(12),CHARACTER_MAXIMUM_LENGTH) + ')' end
from INFORMATION_SCHEMA.COLUMNS
where TABLE_NAME = 'Documentos'
Run Code Online (Sandbox Code Playgroud)
我的结果就是这个
(No column name)
NULL
Declare @DocSerie varchar(5)
NULL
NULL
NULL
NULL
NULL
NULL
NULL
NULL
NULL
NULL
NULL
NULL
NULL
NULL
NULL
NULL
NULL
NULL
NULL
NULL
NULL
NULL
Declare @DocImporteLetras varchar(255)
Declare @DocMotivos text(2147483647)
NULL
Declare @DocDocumentosReferencia varchar(255)
NULL
NULL
Declare @DocAuditoriaIPC varchar(40)
NULL
NULL
Declare @DocAuditoriaIPM varchar(40)
NULL
NULL
NULL
NULL …Run Code Online (Sandbox Code Playgroud) 我正在为之工作的公司有一些巨大的日志/日志表,每10秒左右就会写一次交易.我想要删除此表中的大量数据并将其从该表中删除,因为大约75%的旧数据可以放在存档表或其他内容中,但是如果我这样做错了并且表被锁定了这将是一场灾难.
在之前的一个问题中,一个人想出了类似的东西,我想知道这不会搞砸一切,是否有足够的提示保证我的安全并且所有的写入工作都很好?如果没有,我该怎么办?
set identity_insert newtable on
DECLARE @StartID bigint, @LastID bigint, @EndID bigint
select @StartID = max(id)+1
from newtable
select @LastID = max(ID)
from oldtable
while @StartID < @LastID
begin
set @EndID = @StartID + 1000000
insert into newtable (FIELDS,GO,HERE)
select FIELDS,GO,HERE from oldtable (NOLOCK)
where id BETWEEN @StartID AND @EndId
set @StartID = @EndID + 1
end
set identity_insert newtable off
go
Run Code Online (Sandbox Code Playgroud) 我有一个包含大量数据的表,我们特别关心这个date领域.原因是数据量上升了大约30倍,旧的方式很快就会崩溃.我希望您可以帮助我优化需求的查询:
例如,当前表包含5秒(+/-一点)间隔的数据.我需要对该表进行采样并获得最接近30秒间隔的记录.
我现在所做的工作得很好.我只是好奇是否有办法更优化它.如果我能在Linq To SQL中做到这一点,那也是很好的.考虑到日期值的数量(约200万行最小值),我甚至对索引的建议感兴趣.
declare @st datetime ; set @st = '2012-01-31 05:05:00';
declare @end datetime ; set @end = '2012-01-31 05:10:00';
select distinct
log.* -- id,
from
dbo.fn_GenerateDateSteps(@st, @end, 30) as d
inner join lotsOfLogData log on l.Id = (
select top 1 e.[Id]
from
lotsOfLogData as log -- contains data in 5 second intervals
where
log.stationId = 1000
-- search for dates in a certain range
AND utcTime between DateAdd(s, -10, dt) …Run Code Online (Sandbox Code Playgroud)