Viewing 15 posts - 11,371 through 11,385 (of 15,381 total)
Or maybe when they forget the join condition in a where clause and get a cross join on 2 tables with 1M+ rows each. 😀
Two main reasons:
1) Code is...
July 12, 2012 at 10:56 am
LOL we have all been there. 😉 Glad that helped.
July 12, 2012 at 10:52 am
You can do this pretty easily with a tally table.
select OrderId, ProductId, 1
from #OrderItems o
join Tally t on t.N <= o.Quantity
You can read about a tally table here. http://www.sqlservercentral.com/articles/T-SQL/62867/%5B/url%5D
July 12, 2012 at 10:45 am
bernard75 (7/12/2012)
I guess this somehow landed in the wrong forum. :blush:ELT(): Return string at index number.
Anyway that query returns one of the strings.
ELT is MySql not sql server. I had...
July 12, 2012 at 10:38 am
The whole series of subselects sure makes that far more complicated than it needs to be.
Not sure if what you posted produces what the OP wants but this produces the...
July 12, 2012 at 10:27 am
And be wary of NOLOCK. If there is a good reason you can explain then go for it.
http://blogs.msdn.com/b/davidlean/archive/2009/04/06/sql-server-nolock-hint-other-poor-ideas.aspx
http://www.jasonstrate.com/2012/06/the-side-effect-of-nolock/%5B/url%5D
July 12, 2012 at 8:40 am
SGT_squeequal (7/12/2012)
I used the while loop within while loop worked a treat for what i need 🙂
So with 5 other methods that are faster you still choose to use the...
July 12, 2012 at 8:22 am
New shot in the dark....
declare @PROCINDEX int
select @PROCINDEX = PROCINDEX FROM PROCINDEXCOUNTER
INSERT INTO dbo.ProdHistMaster
( PRODDATE
,PROCESSID
,PARTID
,PROCINDEX
,QUANTITY
,GRS
,UPDATEDBY
,UPDATEDTIME
,INSERIAL
,COMPANY
,QADRecID
)
SELECT
convert(datetime,absdate) as absDate
, 'Pack'
, Item
, ROW_NUMBER() over (order by absDate) + @PROCINDEX
, ItemQty
, 'G'
, 'QAD'
,...
July 12, 2012 at 8:08 am
There still is no need for a cursor here at all. A simple insert using Row_Number() should be totally fine.
July 12, 2012 at 8:02 am
subbareddy542 (7/11/2012)
SELECT DATEADD(MM,DATEDIFF(MM,0,GETDATE()),0)
DECLARE @date datetime = '2012/06/20 11:05:02 PM'
DECLARE @HH INT=SUBSTRING(CONVERT(VARCHAR(10),@DATE,108),1,CHARINDEX(':',CONVERT(VARCHAR(10),@DATE,108))-1)
SELECT CONVERT(CHAR(10), CONVERT(datetime, @date,103),101)+' '+CONVERT(VARCHAR(10),CASE WHEN @date LIKE '% PM' THEN
...
July 12, 2012 at 7:09 am
Lynn Pettis (7/11/2012)
You don't have enough columns in the select list to match the insert columns. Your short one.
Further proof we need ddl and sample data. 😉
July 12, 2012 at 7:04 am
Hard to tell for sure without ddl, sample data and desired output but I think this is pretty much the same thing...
Something like this perhaps?
INSERT INTO dbo.ProdHistMaster
( PRODDATE
,PROCESSID
,PARTID
,PROCINDEX
,QUANTITY
,GRS
,UPDATEDBY
,UPDATEDTIME
,INSERIAL
,COMPANY
,QADRecID
)
SELECT convert(datetime,absdate)...
July 11, 2012 at 3:44 pm
Your insert is outside of the cursor as Lynn pointed out but the bigger question is why do you need a cursor at all? This is a single insert and...
July 11, 2012 at 3:40 pm
adonetok (7/11/2012)
The problem is exec this...
July 11, 2012 at 3:34 pm
Lucky for you I had a few minutes of downtime.
Since there is no sample data or ddl I created my own to demonstrate one approach to this.
create table #Products
(
ProductID int...
July 11, 2012 at 12:59 pm
Viewing 15 posts - 11,371 through 11,385 (of 15,381 total)