Last active
December 18, 2017 14:26
-
-
Save zakizaki-ri9/5570c10ed2cee64ca6d38238889efc22 to your computer and use it in GitHub Desktop.
SQLServerで実行されたSQLやストアドをキャプチャする方法 ref: https://qiita.com/zaki_zaki/items/799928cf0b225b10b4d4
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
use SampleDB | |
if exists(select obj.* from sys.objects as obj where obj.name = N'SampleTable') | |
begin | |
drop table SampleTable | |
end | |
create table SampleTable | |
( | |
id int | |
, sample_name nvarchar(max) | |
, option_a nvarchar(max) | |
) | |
insert into SampleTable select 1, N'AAA', N'' | |
insert into SampleTable select 2, N'BBB', N'a' | |
insert into SampleTable select 3, N'CCC', N'' | |
insert into SampleTable select 4, N'AAA', N'a' |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
USE SampleDB | |
SET ANSI_NULLS ON | |
GO | |
SET QUOTED_IDENTIFIER ON | |
GO | |
DROP PROCEDURE GetSampleTable | |
GO | |
CREATE PROCEDURE GetSampleTable | |
@sample_name NVARCHAR(MAX) = null | |
, @option_a NVARCHAR(MAX) = null | |
AS | |
BEGIN | |
SET NOCOUNT ON; | |
SELECT * FROM SampleTable WHERE | |
(@sample_name IS NULL OR sample_name = @sample_name) AND | |
(@option_a IS NULL OR option_a = @option_a) | |
END | |
GO |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
private string CreateConnectionString() | |
{ | |
// 接続文字列生成 | |
var conStrBuilder = new SqlConnectionStringBuilder() | |
{ | |
DataSource = "localhost", | |
InitialCatalog = "SampleDB", | |
UserID = "sa", | |
Password = "pass" | |
}; | |
return conStrBuilder.ToString(); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment