tsql

SQL Update table with cumulative value

百般思念 提交于 2021-02-08 05:14:17
问题 I have this table: Date |StockCode|DaysMovement|OnHand 29-Jul|SC123 |30 |500 28-Jul|SC123 |15 |NULL 27-Jul|SC123 |0 |NULL 26-Jul|SC123 |4 |NULL 25-Jul|SC123 |-2 |NULL 24-Jul|SC123 |0 |NULL The reason only the top row has an OnHand value is because I can get this from another table that stores the current qty on hand for any stock code. The other records in the table are taken from another table that logs all the movement for any given day. I want to update the above table so that the OnHand

How to query XML as used in .dtsx (SSIS)

◇◆丶佛笑我妖孽 提交于 2021-02-08 03:42:31
问题 I have made an SSIS 2014 package (Project Deployment). Here you see a (relevant) part of it's XML-content: <DTS:Executable DTS:refId="Package\Drop and Create statements voor tabellen\Drop and Create Classes_staging" DTS:CreationName="Microsoft.ExecuteSQLTask" DTS:Description="Execute SQL Task" DTS:DTSID="{60C174A8-D9C0-4F2A-B783-77753552BFCB}" DTS:ExecutableType="Microsoft.ExecuteSQLTask" DTS:LocaleID="-1" DTS:ObjectName="Drop and Create Classes_staging" DTS:TaskContact="Execute SQL Task;

tsql how to split xml and insert them as rows

﹥>﹥吖頭↗ 提交于 2021-02-08 02:13:33
问题 There was a question here (How to update all xml attributes' value in an xml variable using t-sql?) where the questioner wanted to split an xml variable into rows. I have almost the same problem, but I'm storing the xmls in a table. Every row stores at least 1 xml node, sometimes more. I want to split them to separate rows, but it seems like .nodes('a') needs a scalar variable. This is what I've tried: declare @T table (XMLCol xml); insert into @T values ('<a abb="122"> <b></b> </a> <a abb=

tsql how to split xml and insert them as rows

 ̄綄美尐妖づ 提交于 2021-02-08 02:13:04
问题 There was a question here (How to update all xml attributes' value in an xml variable using t-sql?) where the questioner wanted to split an xml variable into rows. I have almost the same problem, but I'm storing the xmls in a table. Every row stores at least 1 xml node, sometimes more. I want to split them to separate rows, but it seems like .nodes('a') needs a scalar variable. This is what I've tried: declare @T table (XMLCol xml); insert into @T values ('<a abb="122"> <b></b> </a> <a abb=

Error converting data type varchar to float

杀马特。学长 韩版系。学妹 提交于 2021-02-07 20:33:49
问题 Searched and searched on SO and can't figure it out Tried CASTING each field as FLOAT to no avail, convert didn't get me any further How can I get the below case clause to return the value stated in the THEN section? Error: Msg 8114, Level 16, State 5, Line 1 Error converting data type varchar to float. section of my SQL query that makes it error: When cust_trendd_w_costsv.terms_code like '%[%]%' and (prod.dbo.BTYS2012.average_days_pay) - (substring(cust_trendd_w_costsv.terms_code,3,2)) <= 5

Error converting data type varchar to float

非 Y 不嫁゛ 提交于 2021-02-07 20:33:47
问题 Searched and searched on SO and can't figure it out Tried CASTING each field as FLOAT to no avail, convert didn't get me any further How can I get the below case clause to return the value stated in the THEN section? Error: Msg 8114, Level 16, State 5, Line 1 Error converting data type varchar to float. section of my SQL query that makes it error: When cust_trendd_w_costsv.terms_code like '%[%]%' and (prod.dbo.BTYS2012.average_days_pay) - (substring(cust_trendd_w_costsv.terms_code,3,2)) <= 5

BULK INSERT with two row terminators

≡放荡痞女 提交于 2021-02-07 19:43:41
问题 I am trying to import a text file, so the result would be just words in a seperate rows of one column. For example a text: 'Hello Mom, we meet again' should give 5 records: 'Hello' 'Mom,' 'we' 'meet' 'again' I tried to accomplish this with BULK INSERT with ROWTERMINATOR = ' ' , but there is a problem with treating new line as a terminator too and I get 'Mom,we' in one of the results. From what i know, there is no way to add a second ROWTEMRMINATOR to BULK INSERT (true?). What is the best way

LINQ: The cast to value type 'System.Int32' failed because the materialized value is null

微笑、不失礼 提交于 2021-02-07 14:25:59
问题 I'm getting the following error when executing a LINQ query on my database: The cast to value type 'System.Int32' failed because the materialized value is null. I believe it's because one of the columns is returning a null. Here is my LINQ command: var facts = (from b in Program.db.ProductBrands join bm in Program.db.BrandManufacturers on b.ProductBrandID equals bm.ProductBrandID join c in Program.db.Companies on bm.ProductManufacturerID equals c.CompanyID join s in Program.db.AnimalSources

LINQ: The cast to value type 'System.Int32' failed because the materialized value is null

淺唱寂寞╮ 提交于 2021-02-07 14:24:20
问题 I'm getting the following error when executing a LINQ query on my database: The cast to value type 'System.Int32' failed because the materialized value is null. I believe it's because one of the columns is returning a null. Here is my LINQ command: var facts = (from b in Program.db.ProductBrands join bm in Program.db.BrandManufacturers on b.ProductBrandID equals bm.ProductBrandID join c in Program.db.Companies on bm.ProductManufacturerID equals c.CompanyID join s in Program.db.AnimalSources

Why use NOLOCK and NOWAIT together?

心已入冬 提交于 2021-02-07 13:57:20
问题 A colleague wrote a query which uses the hints "with (NOLOCK,NOWAIT)". e.g. select first_name, last_name, age from people with (nolock,nowait) Assumptions: NOLOCK says "don't worry about any locks at any level, just read the data now" NOWAIT says "don't wait, just error if the table is locked" Question: Why use both at the same time? Surely NOWAIT will never be realised, as NOLOCK means it wouldn't wait for locks anyway ... ? 回答1: It's redundant (or at least, ineffective). In one query window