gpt4 book ai didi

c# - 如何在不断错误的情况下设置一个sql字符串而不换行

转载 作者:太空宇宙 更新时间:2023-11-03 18:33:05 30 4
gpt4 key购买 nike

这很愚蠢,但我正在为一个 sql 命令声明一个 sql 字符串,我必须将它全部写在一行上,如下所示

string strSQL = "SELECT [Year],[Week No],StartDate,EndDate,Dept,[Clock No],RTRIM(Name)+' '+   RTRIM(initial) as Name,[Own Hours],[Other Hours],[Total Hours],[OT Premium] FROM [Wages].[CHHours] Where [Year]=@WageYear and [Week No]=@Week Order by  [Year] DESC, [Week No] DESC,Dept,[Clock No]" ;

因为否则我会不断出现换行符错误,但这看起来非常难看且难以阅读。在 vb 中,它会使用 &_ 继续,因为 c# 对空格不敏感(我想)我应该这样写

string strSQL = "SELECT [Year],[Week No],StartDate,EndDate,Dept,[Clock No],
RTRIM(Name)+' '+ RTRIM(initial) as Name,[Own Hours],[Other Hours],
[Total Hours],[OT Premium]
FROM [Wages].[CHHours]
Where [Year]=@WageYear and [Week No]=@Week
Order by [Year] DESC, [Week No] DESC,Dept,[Clock No]" ;

或者我必须做些什么

string strSQL = "SELECT [Year],[Week No],StartDate,EndDate,Dept,[Clock No],";

string strSQL = strSQL+" RTRIM(Name)+' '+ RTRIM(initial) as Name,[Own Hours]";

string strSQL = strSQL+",[Other Hours],[Total Hours],[OT Premium] ";

string strSQL = strSQL+"FROM [Wages].[CHHours] ";

string strSQL = strSQL+" Where [Year]=@WageYear and [Week No]=@Week ";

string strSQL = strSQL+"Order by [Year] DESC, [Week No] DESC,Dept,[Clock No]" ;

这让我觉得很古老!

请问最好的方法是什么伊恩

最佳答案

使用@符号,例如

string strSQL = @"SELECT [Year],[Week No],StartDate,EndDate,Dept,[Clock No],
RTRIM(Name)+' '+ RTRIM(initial) as Name,[Own Hours],[Other Hours],
[Total Hours],[OT Premium]
FROM [Wages].[CHHours]
Where [Year]=@WageYear and [Week No]=@Week
Order by [Year] DESC, [Week No] DESC,Dept,[Clock No]" ;

这可能行得通吗?

关于c# - 如何在不断错误的情况下设置一个sql字符串而不换行,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19589744/

30 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com