SQL 字串拼接中換行處理

2021-08-26 12:09:40 字數 1308 閱讀 3333

今天碰到乙個問題,需要在sql server中用print列印出需要的資訊,其中要求每一條資訊完了之後換行,想到可以用字串拼接,然後在字串中新增換行處理。如下:

declare  @count_details int

declare @count_assetplan int

declare @count_principal int

declare @count_interest int

set @count_details = ( select count(distinct dimloanid) from trustmanagement.trustmanagement.tblassetdetails_new where trustid = 157 )

set @count_assetplan = ( select count( distinct dimloanid) from trustmanagement.asset.trustassetpaymentplan_new where trustid = 157 )

set @count_principal = ( select count( distinct dimloanid) from trustmanagement.asset.principalschedule_new where trustid = 157)

set @count_interest = ( select count( distinct dimloanid ) from trustmanagement.asset.interestschedule_new where trustid = 157 )

if @count_details = @count_assetplan and @count_assetplan = @count_principal and @count_principal = @count_interest

print n'完全拆分'

else

print n'不完全拆分'

print ' count_details ' + convert(nvarchar, @count_details ) + char(13) +

' count_assetplan ' + convert(nvarchar, @count_assetplan ) + char(13) +

' count_principal ' + convert(nvarchar, @count_principal ) + char(13) +

' count_interest ' + convert(nvarchar, @count_interest )

SQL 拼接字串

寫sql的時候有時候用到需要拼接多個字段或者在查詢出結果的字段裡加入一部分固定的字串。方法一 在查詢到的結果後,用 去拼接。這種方法就不在贅述。方法二 使用資料庫提供的方法concat a,b oracle 中concat a,b 只能有兩個引數,如果concat中連線的值不是字串,那麼oracle...

sql字串拼接

oracle 使用 或者concat sql select aaa bbb from dual aaa bbb aaabbb sql select concat aaa ccc from dual concat aaa aaaccc mysql中,使用 如果字串全是數字則轉化為數字,否則轉換為0,也...

sql字串拼接

在sql語句中經常需要進行字串拼接,以sqlserver,oracle,mysql三種資料庫為例,因為這三種資料庫具有代表性。sqlserver select 123 456 oracle select 123 456 from dual 或select concat 123 456 from du...