この長いスクリプトのフォーマットソリューションを尋ねることはできますか?私はここでASPの新機能は、PHPでは長いスクリプトを宣言するときにPHPで異なるため、コピー&ペーストするだけで大丈夫です。しかし、ASPで。スクリプトは長い行にする必要があります。 サンプルスクリプトを問題asp.net要件を解決する変数(ASP.NET MVC RAZOR)に長いクエリを貼り付けたときにエラーが発生します
サンプルスクリプト
String sql = "SELECT
timesheet.date,
MAX(CASE
WHEN timein1 = 8 and note ='HOLIDAY' and counter = 1
then (SELECT description FROM holidays WHERE timesheet.date = holidays.date)
WHEN timein1 = 8 and note ='SICK LEAVE' and counter =1 then 'SICK LEAVE'
WHEN timein1 = 8 and note ='VACATION LEAVE' and counter =1 then 'VACATION LEAVE'
WHEN timein1 = 8 and note ='REGULAR LOGGED' and counter =1 then log
END) as note1,
MAX(case
WHEN timeout1 = 12 and note ='HOLIDAY' and counter =2
then (SELECT description FROM holidays WHERE timesheet.date = holidays.date)
WHEN timeout1 = 12 and note ='SICK LEAVE' and counter =2 then 'SICK LEAVE'
WHEN timeout1 = 12 and note ='VACATION LEAVE' and counter =2 then 'VACATION LEAVE'
WHEN timeout1 = 12 and note ='REGULAR LOGGED' and counter =2 then log
else ''
end) as note2,
MAX(case
WHEN timein2 = 13 and note ='HOLIDAY' and counter =3
then (SELECT description FROM holidays WHERE timesheet.date = holidays.date)
WHEN timein2 = 13 and note ='SICK LEAVE' and counter =3 then 'SICK LEAVE'
WHEN timein2 = 13 and note ='VACATION LEAVE' and counter =3 then 'VACATION LEAVE'
WHEN timein2 = 13 and note ='REGULAR LOGGED' and counter =3 then log
else ''
end) as note3,
MAX(case
WHEN timeout2 = 17 and note ='HOLIDAY' and counter =4
then (SELECT description FROM holidays WHERE timesheet.date = holidays.date)
WHEN timeout2 = 17 and note ='SICK LEAVE' and counter =4 then 'SICK LEAVE'
WHEN timeout2 = 17 and note ='VACATION LEAVE' and counter =4 then 'VACATION LEAVE'
WHEN timeout2 = 17 and note ='REGULAR LOGGED' and counter =4 then log
else ''
end) as note4
FROM timesheet
LEFT JOIN schedules ON timesheet.empid = schedules.empid
WHERE timesheet.empid='40' and YEAR(timesheet.date) = 2017
AND MONTH(timesheet.date) = 5
AND timesheet.date <= CURDATE()
AND timeStatus='OK'
GROUP BY timesheet.date,timesheet.empid "
この
SELECT timeshet.date、MAX(CASE timein1 = 8であり、= 'HOLIDAY' およびカウンタを注意します= 1などなどなど............長い文字列を連結するには3一般的な方法があります
以下に述べるように、@を使用することができます。 –
ストアプロシージャを作成すると、そのストアプロシージャを実行するだけで済みます。とても清潔です。 –
リテラル文字列 'String sql = @" SELECT ... "を使用して、クエリを複数の行にまとめます。しかし、私はORM/'SqlConnection'からストアドプロシージャと呼び出しを作成する方が好きです。 –