需求:解析CSV文件并忽略引号内的逗号
解决方案:
public static void main(String[] args) { String s = "a,b,c,\"1,000\""; String[] result = s.split(",(?=([^\"]*\"[^\"]*\")*[^\"]*$)"); for (String str : result) { System.out.println(str); } }
输出:
a
b
c
“1,000”
Use this BCP script to generate CSV file:
bcp "SELECT ''ID'', ''Username'' UNION ALL SELECT CAST(u.ID as varchar(10)),u.USERNAME from DavidTest.dbo.DavidUser u" queryout "c:\output.csv" -c -t"," -r"\n" -SServerName -T
If you want to run in SSMS, you can use:
USE MASTER
GO
DECLARE @query varchar(4000)
SET @query = '"SELECT...."';
EXEC xp_cmdshell @bcpOut
GO
for more info:
http://msdn.microsoft.com/en-us/library/aa174646(v=sql.80).aspx
// Proudly powered by Apache, PHP, MySQL, WordPress, Bootstrap, etc,.