sql-server-2012

How do I capture the data passed in SqlBulkCopy using the Sql Profiler?

左心房为你撑大大i 提交于 2020-01-22 11:58:26
问题 I am using Sql Profiler all the time to capture the SQL statements and rerun problematic ones. Very useful. However, some code uses the SqlBulkCopy API and I have no idea how to capture those. I see creation of temp tables, but nothing that populates them. Seems like SqlBulkCopy bypasses Sql Profiler or I do not capture the right events. 回答1: Capturing event info for bulk insert operations ( BCP.EXE , SqlBulkCopy , and I assume BULK INSERT , and OPENROWSET(BULK... ) is possible, but you won't

Sql server - recursive delete

淺唱寂寞╮ 提交于 2020-01-20 17:30:11
问题 I'm trying to delete user's data and all it's related data that is located in different tables. All the tables have Foreign Keys but without cascade delete. I investigated some options: Enable cascade delete on all FK, delete and remove the cascade delete. Delete from bottom UP, loop up for all the leaves delete and repeat this operation till Root. Are there any more smart option or other Techniques? I'm using Microsoft SQL Server 2012 (SP1) 回答1: Oracle solution: How to generate DELETE

Create a user defined table type in c# to use in sql server stored procedure

橙三吉。 提交于 2020-01-19 11:38:27
问题 I'm trying to write a c# program which creates a whole table to send back to a sql server stored procedure. I came across the msdn guide but became incredibly confused: http://msdn.microsoft.com/en-us/library/cc879253.aspx I tried to use the msdn guide but get an error despite adding references to microsoft.sqlserver.smo, microsoft.sqlserver.connectioninfo, microsoft.sqlserver.management.sdk.sfc as suggested by the compiler. The error is: "Set parent failed for userdefinedtabletype". (code

Create a user defined table type in c# to use in sql server stored procedure

浪尽此生 提交于 2020-01-19 11:37:50
问题 I'm trying to write a c# program which creates a whole table to send back to a sql server stored procedure. I came across the msdn guide but became incredibly confused: http://msdn.microsoft.com/en-us/library/cc879253.aspx I tried to use the msdn guide but get an error despite adding references to microsoft.sqlserver.smo, microsoft.sqlserver.connectioninfo, microsoft.sqlserver.management.sdk.sfc as suggested by the compiler. The error is: "Set parent failed for userdefinedtabletype". (code

SQL Grouping Acct Numbers and Getting Subtotals and Grand Total

梦想的初衷 提交于 2020-01-17 08:11:05
问题 This query... SELECT ACTNO,SUM(PLAN) AS 'TOTAL PLAN', SUM(FORECAST) AS 'TOTAL FORECAST' FROM COST_CENTER GROUP BY ACTNO I get the following results: ACTNO | TOTAL PLAN | TOTAL FORECAST 100 | 12000 | 20000 101 | 12000 | 20000 200 | 1000 | 1500 201 | 1200 | 2000 202 | 900 | 1500 203 | 700 | 1500 220 | 1500 | 3500 300 | 1200 | 2000 301 | 1000 | 3000 I need to group together certain accounts, get those groups' subtotals, and then add all the subtotals up for a grand total. The desired result

Error in Sql store procedure

ⅰ亾dé卋堺 提交于 2020-01-17 06:09:46
问题 INSERT INTO Tbl_Basicinfo(Employer_Id,Lname,Fname,UserName,Userpass,Location_Id,cc2,CC3,cc4,cc5,Dohire,Job_Status,ssn,Import_Emp_No,[Benefit_Terminate], [Show_Age], [Change_IP], [IsNewHired]) SELECT M.Employer_Id,M.LASTNAME,M.FIRSTNAME,UPPER(LEFT(ISNULL(M.FIRSTNAME,'A'),1)+''+LEFT(ISNULL(M.LASTNAME,'C'),1))+CONVERT(VARCHAR,MaxImportEENumber+ROWNUM) [UserName],RIGHT(NEWID(),10) [UserPass],ISNULL(M.Location_Id,0)[Location_Id],M.Level2code,M.Level3code,M.LEVEL4Code,M.LEVEL5Code,M.DATEOFHIRE, 1

Error in Sql store procedure

依然范特西╮ 提交于 2020-01-17 06:09:10
问题 INSERT INTO Tbl_Basicinfo(Employer_Id,Lname,Fname,UserName,Userpass,Location_Id,cc2,CC3,cc4,cc5,Dohire,Job_Status,ssn,Import_Emp_No,[Benefit_Terminate], [Show_Age], [Change_IP], [IsNewHired]) SELECT M.Employer_Id,M.LASTNAME,M.FIRSTNAME,UPPER(LEFT(ISNULL(M.FIRSTNAME,'A'),1)+''+LEFT(ISNULL(M.LASTNAME,'C'),1))+CONVERT(VARCHAR,MaxImportEENumber+ROWNUM) [UserName],RIGHT(NEWID(),10) [UserPass],ISNULL(M.Location_Id,0)[Location_Id],M.Level2code,M.Level3code,M.LEVEL4Code,M.LEVEL5Code,M.DATEOFHIRE, 1

Data is splitting into multiple rows while copying from sql server 2012 to excel sheet

北慕城南 提交于 2020-01-16 20:05:18
问题 SQl Query : select REPLACE(REPLACE(cast(description as nvarchar(max)), CHAR(10), ''), CHAR(13), '')[description] From EuroRawData where message like '%Dewan Sabuj%' Description column is ntext. Without using replace the result was this : অনেক সময় প্রিয়জনের মোবাইলে টাকা দেয়ার প্রয়োজন হয়। কিন্তু তখন যদি দেখেন ফ্লেক্সিলোড দেওয়া যাচ্ছে না – তাহলে তো সমস্যা । তবে এখন আপনি আপনার স্ক্র্যাচ কার্ড দিয়েই বন্ধুর মোবাইলে রিচার্জ করে দিতে পারবেন । আপনাকে যা করতে হবেঃ- ▄► জিপির গ্রাহকদের জন্য : ডায়াল

Data is splitting into multiple rows while copying from sql server 2012 to excel sheet

我的未来我决定 提交于 2020-01-16 20:04:20
问题 SQl Query : select REPLACE(REPLACE(cast(description as nvarchar(max)), CHAR(10), ''), CHAR(13), '')[description] From EuroRawData where message like '%Dewan Sabuj%' Description column is ntext. Without using replace the result was this : অনেক সময় প্রিয়জনের মোবাইলে টাকা দেয়ার প্রয়োজন হয়। কিন্তু তখন যদি দেখেন ফ্লেক্সিলোড দেওয়া যাচ্ছে না – তাহলে তো সমস্যা । তবে এখন আপনি আপনার স্ক্র্যাচ কার্ড দিয়েই বন্ধুর মোবাইলে রিচার্জ করে দিতে পারবেন । আপনাকে যা করতে হবেঃ- ▄► জিপির গ্রাহকদের জন্য : ডায়াল

Reduce cost for Table Valued Function - XML Reader in query plan - how?

你说的曾经没有我的故事 提交于 2020-01-16 09:43:10
问题 I have the below SQL Server query: with cte as (SELECT DISTINCT refrecid FROM docuref WHERE ACTUALCOMPANYID = 'an' and REFTABLEID='78' and typeid='Note') SELECT docuref.REFRECID, Notes = STUFF ((SELECT CHAR(13) + CHAR(10) + cast([NOTES] AS nvarchar(max)) FROM DOCUREF WHERE REFRECID = Cte.refrecid AND ACTUALCOMPANYID = 'an' FOR XML PATH(''), TYPE ).value('.', 'nvarchar(max)'), 1, 2, '') FROM Cte INNER JOIN DOCUREF ON cte.REFRECID= docuref.REFRECID WHERE DOCUREF.ACTUALCOMPANYID = 'an' and