Skip to content

Instantly share code, notes, and snippets.

//In Service
using (var scope = _serviceScopeFactory.CreateScope())
{
var dbContext = scope.ServiceProvider.GetRequiredService<RicoDbContext>();
await dbContext.Products.AddAsync(product)
.ConfigureAwait(false);
var serial = product.Serial;
return await dbContext.SaveChangesAsync()
.ConfigureAwait(false);
}
Create or alter proc [dbo].[usp_spaceused]
@objname nvarchar(776) = null
as
declare @id int -- The object id that takes up space
,@type character(2) -- The object type.
,@pages bigint -- Working variable for size calc.
,@dbname sysname
,@dbsize bigint
,@logsize bigint
,@reservedpages bigint
--結果表
declare @result table(rownums int,TITLE_ID varchar(10),DATEX varchar(10),DC varchar(1),ST int,D_AMT int,C_AMT int, total int default(0))
;with mycte
as
(
select rownums=ROW_NUMBER() over (partition by a.TITLE_ID order by a.TITLE_ID),
a.TITLE_ID,b.DATEX,a.DC,a.ST,b.D_AMT,b.C_AMT,0 as total
from ta a join td b
on a.TITLE_ID=b.TITLE_ID
)
CREATE OR ALTER PROCEDURE [usp_ConvertTableToClass]
@tablename SYSNAME,@namespace varchar(50)
AS
SET NOCOUNT ON
DECLARE @step int,@maxcount int
DECLARE @temp TABLE
(
codeline INT,
code nvarchar(4000)
)
declare @result table
(
serial int identity(1,1),
owner varchar(100),
tname varchar(500),
sname varchar(100)
)
insert into @result
select sch.name as 'Owner',obj.name as '資料表名稱',st.name as '統計值名稱'
create function [dbo].[myStrSplit]
(
@inputcontent nvarchar(max),
@schar char(1)
)
RETURNS TABLE
as
return
(
with mysplie(i,j)
select GETDATE()
go
--使用cursor串連
declare
@owner varchar(100),
select GETDATE()
go
--使用XML 串連
declare @s nvarchar(max) = N'';
select GETDATE()
go
--使用直接串連
declare @s nvarchar(max) = N'';
SELECT @s += CHAR(13) + CHAR(10) + 'drop statistics '
select GETDATE()
go
--使用while loop
declare @result table
(