Quantcast
Channel: SQLServerCentral » SQL Server 2012 » SQL Server 2012 - T-SQL » Latest topics
Viewing all 4901 articles
Browse latest View live

CTE to determine Course Level

$
0
0
Okay, before someone asks, this is not homework... I just can't figure out how to do it. :-)I have two tables, Courses and Prerequisites. Each Course may have zero or more Prerequisites.Here are my table definitions:CREATE TABLE [dbo].[Course]( [CourseID] [char](7) NOT NULL, CONSTRAINT [pk_Course] PRIMARY KEY CLUSTERED ( [CourseID] ASC)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]) ON [PRIMARY];USE [Courses]GO/****** Object: Table [dbo].[Prereq] Script Date: 8/24/2013 9:40:18 PM ******/SET ANSI_NULLS ONGOSET QUOTED_IDENTIFIER ONGOSET ANSI_PADDING ONGOCREATE TABLE [dbo].[Prereq]( [NextCourseID] [char](7) NOT NULL, [ReqCourseID] [char](7) NOT NULL, CONSTRAINT [pk_Prereq] PRIMARY KEY CLUSTERED ( [NextCourseID] ASC, [ReqCourseID] ASC)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]) ON [PRIMARY]GOALTER TABLE [dbo].[Prereq] WITH CHECK ADD FOREIGN KEY([NextCourseID])REFERENCES [dbo].[Course] ([CourseID])GOALTER TABLE [dbo].[Prereq] WITH CHECK ADD FOREIGN KEY([ReqCourseID])REFERENCES [dbo].[Course] ([CourseID])GOINSERT INTO Course (CourseID) VALUES ('503'); -- no prereqsINSERT INTO Course (CourseID) VALUES ('515'); -- no prereqsINSERT INTO Course (CourseID) VALUES ('601'); -- no prereqsINSERT INTO Course (CourseID) VALUES ('604');INSERT INTO Course (CourseID) VALUES ('605');INSERT INTO Course (CourseID) VALUES ('606');INSERT INTO Course (CourseID) VALUES ('607');INSERT INTO Course (CourseID) VALUES ('608');INSERT INTO Course (CourseID) VALUES ('608');/* Prerequisites */INSERT INTO Prereqs (NextCourseID, ReqCourseID) VALUES ('503','515');INSERT INTO Prereqs (NextCourseID, ReqCourseID) VALUES ('604','503');INSERT INTO Prereqs (NextCourseID, ReqCourseID) VALUES ('605','503');INSERT INTO Prereqs (NextCourseID, ReqCourseID) VALUES ('608','503');INSERT INTO Prereqs (NextCourseID, ReqCourseID) VALUES ('604','601');INSERT INTO Prereqs (NextCourseID, ReqCourseID) VALUES ('620','605');INSERT INTO Prereqs (NextCourseID, ReqCourseID) VALUES ('620','608');INSERT INTO Prereqs (NextCourseID, ReqCourseID) VALUES ('606','605');What I was trying to do was to use a recursive CTE to determine the level of each course in the hierarchy (implied by the Prereqs). A course without Prereqs would be level 1, and any requiring only level 1's would be a 2.This is what I tried...-- courses without prereqsWITH PrereqsCTE (CourseID, Depth) AS( SELECT c.CourseID, 0 AS Lvl FROM Course c WHERE NOT EXISTS (SELECT * FROM Prereq WHERE NextCourseID = c.CourseID)UNION ALL SELECT p.NextCourseID, Depth + 1 FROM Prereq p INNER JOIN PrereqsCTE ON p.NextCourseID = PrereqsCTE.CourseID)SELECT CourseID, DepthFROM PrereqsCTE;the first part (with the NOT EXISTS) works, but I can't figure out how to get the recursive part to work. I read a bunch of CTE articles (I think Chris M wrote one, and then a post that G Squared posted, and I still couldn't figure it out!)... I guess I'm not sure how to hook the recursive member to the anchor... I thought it was in a join ... but I'm clearly missing something.Could someone please enlighten me?Thanks!Pieter

SQL SERVER Subquery Error

$
0
0
Once I run this query, I get the following error.DECLARE@Type int,@SearchStr2 nvarchar(200)SET @SearchStr2 = 'A'SELECT * FROM Document WHERE DocNo in(CASE @Type WHEN 1 THEN (SELECT DocNO FROM Publisher WHERE CONTAINS((PublisherName), @SearchStr2) ) WHEN 2 THEN (SELECT DocNO FROM Publisher WHERE CONTAINS((PublishedPlace), @SearchStr2) ) WHEN 3 THEN (SELECT DocNO FROM Publisher WHERE CONTAINS((PublishedDate), @SearchStr2) ) END )Msg 512, Level 16, State 1, Line 4 Subquery returned more than 1 value. This is not permitted when the subquery follows =, !=, <, <= , >, >= or when the subquery is used as an expression.I Find that CASE @Type WHEN ... END needs to evaluate to one value but My sub queries aren't doing that.Now,How can I correct the query?

How to return list of all courses for which a student meets all the prerequisites.

$
0
0
Sorry for the lame title. This is somewhat of a follow-on from a previous post, which is here [url]http://www.sqlservercentral.com/Forums/Topic1488185-3077-1.aspx[/url] It deals with the same tables: Student, Course, Prerequisite, Grades.I was trying to work out a reasonable way to return the list of courses a student met all the prerequisites to take, and am close (I think... but then I've been wrong before!) and was looking for a few ideas. This is part of the way there, as it returns True/False for courses for which a student meets all the prerequisites.[code="sql"]DECLARE @NextCourseID CHAR(7)='605';DECLARE @StudentID INT = 1;-- it would make sense to do a (NOT) EXISTS to check for missing valuesIF EXISTS ( SELECT ReqCourseID, G.Grade FROM Prereq P LEFT JOIN Grades G ON P.ReqCourseID = G.CourseID WHERE NextCourseID = @NextCourseID AND G.StudentID = @StudentID AND G.Grade>=2 /* 2.0 here is a passing grade */) BEGIN PRINT 'True' ENDELSE BEGIN PRINT 'False' END[/code](Sorry it's incomplete... one step at a time!) Should I follow SQLKiwi's article on "[url=http://www.sqlservercentral.com/articles/APPLY/69953/]Understanding Apply[/url]", as I think that will solve the problem. I guess it's just totally uncharted territory for me.The other way I was thinking of trying to do it was to outer join Prereqs to Courses, then eliminate any courses where the grade for the prerequisite course either NULL or not a pass.So how would you approach this problem? (no need to do it for me... I need to learn to do it myself!)Thanks!Pieter

JOB ISSUE ON 2012

$
0
0
I have created one ssis on 2012 .in this packse i have added one cube processing task after that i had run that time it was working fine.after that i have scheduled that job on sql agent that time it was failed.Error:a connection cannot be made ensure that the server is runningwho to reslove these issue.

How many columns in INCLUDED Index are 'Too Many' ???

$
0
0
Dear All,I have a query that takes [b]22 seconds[/b].If I create below index then query finishes in [b]5 seconds[/b], but I'm told that this type of index can't be used as there are too many columns in INCLUDED and it will consume a lot of space.Can anybody please guide me on this.[i][b]CREATE NONCLUSTERED INDEX [test_idx]ON [dbo].[work_order] ([buyer_code])INCLUDE ([job_seeker_id],[start_date],[end_date],[worker_id],[sequence],[work_order_id],[status],[creator_id],[bu_id],[actual_end_date],[site_id],[service_type],[new_requisition_owner_id],[work_order_ref],[primary_cost_center_id],[buyer_ref],[supplier_ref],[equipment_flag])GO[/b][/i]Table work_order has 131 columns and few million records.Regards.

Removing Overlapping periods

$
0
0
Hi, I have a problem and I have created a solution using loops. I would like it to be more efficient if possible. The explanation of the problem is in the code below. If any one can come up with a better solution I would be very appreciative!/****Create sample table of Intervals********************/ IF Object_ID('tempdb.dbo.#Intervals') is not null Drop table #Intervals Create table #Intervals (ID Int Not null,PeriodBegin INT not null,PeriodEnd INT not null)Declare @id int = 1Declare @PeriodBegin INT = 1Declare @i int = 0While @i <= 2000BeginINSert into #Intervals Select id = @id, PeriodBegin = @PeriodBegin+ @i,PeriodEnd = @PeriodBegin+ @i+ 62Set @i = @i + 1ENDSelect * FROM #Intervals/****************************For the above table I need to retain only the records that do not overlap a previous period starting with periodBegin = 1.The next 63 rows have a period begin less than the 1st row's period end, so those rows will be removed.The next valid row would be row 64 as the period begin is less than the first row's period end.I have a method of doing this below but it uses a loop and the tables that I am doing this for have millions of rows in some cases so it is not as efficient as I would like.I cannot just choose the 1st, 64th,127th...etc. rows because not every ordinal value will be represented in the period begin column, the length of the period will always remain consistent however.Can anyone come up with a faster method for doing this??? *********************************************************************************************************/IF Object_ID('tempdb.dbo.#UniqueIntervals') is not null Drop table #UniqueIntervalsCreate table #UniqueIntervals (ID Int Not null,PeriodBegin INT not null,PeriodEnd Int Not null)Declare @loop int = 1While @loop <= 32 ---32 possible unique periodsBegin Insert into #UniqueIntervals (id, PeriodBegin,PeriodEnd ) Select id, PeriodBegin = Min(PeriodBegin), PeriodENd = Min(PeriodEnd) FROM #Intervals Group by id order by Min(PeriodBegin) Delete b FROM #UniqueIntervals a INNER JOIN #Intervals b ON a.id = b.id and b.PeriodBegin <= a.PeriodEndSet @loop = @loop + 1ENDSelect * FROM #UniqueIntervals/************************************************************************/

cross tab query

$
0
0
Hi All,I have a below table structurecpr attendance_Date attendance_Time Trans_Type123 20-Aug-13 8:8:10 I123 20-Aug-13 6:10:10 O123 21-Aug-13 8:10:10 I123 21-Aug-13 7:8:10 O123 22-Aug-13 5:5:10 Oexpected outputcpr attendance_date trans_type123 20-Aug-13 In Out123 21-Aug-13 In Out123 22-Aug-13 Null Outany help is highly appreciated.regards

Strange 'order by' - can anyone explain ?

$
0
0
Hi - I simply don't understand this sorting... Do you know why ?[code="sql"]IF OBJECT_ID('tempdb.dbo.#abthja_1') IS NOT NULLBEGIN DROP TABLE #abthja_1ENDCREATE TABLE #abthja_1 ( postkasse varchar (15) not null,folder varchar(15) not null,modtaget int,lost int)IF OBJECT_ID('tempdb.dbo.#abthja_2') IS NOT NULLBEGIN DROP TABLE #abthja_2ENDCREATE TABLE #abthja_2 ( postkasse varchar (15) not null,folder varchar(15) not null,modtaget int,lost int)insert into #abthja_1 select 'Salg','AAA', 1, NULLunion all select 'Salg','CCC', 2, NULLunion all select 'Salg','BBB', 2, NULLselect * from #abthja_1insert into #abthja_2 select 'Salg','AAA/Lo', NULL, 4union all select 'Salg','CCC', NULL, 5union all select 'Salg','BBB/Lo', NULL, 6select * from #abthja_2select postkasse, folder, sum(modtaget) as modtaget, sum(lost) as lost from ( select * from #abthja_1 union all Select * from #abthja_2) data group by postkasse, folder order by postkasse, folder [/code]Result:[code="plain"]postkasse folder modtaget lostSalg BBB 2 NULLSalg BBB/Lo NULL 6Salg CCC 2 5Salg AAA 1 NULLSalg AAA/Lo NULL 4[/code]If you change BBB to 2BB,AAA to 1AA CCC to 3CCthen you got what you would expect ?Regards from Copenhagen.

Update/Case query help

$
0
0
Hi,I am trying to write an update query but not able to get the result as I want. Any help is much appreciated.I have 2 table as shown belowTABLE 1:ServerName DomainA XB XC YD YE ZF ZTABLE 2:ServerName DomainA XB XC XD YE YF ZThe domains are different in table 2 for the same servernames. All I am trying to do is to update the domain column in Table 2 same as Table 1 (as domain column in Table 1 is accurate) for all the matching servers and for the servers not matching I want to update it as Unknown.Thank youRenuka

Parse XML

$
0
0
Hello! I have some XML I need to parse and am having trouble sorting out how. I will need to parse a few hundred rows at a time and each row contains XML like the following snippet:<feed xmlns:im="http://itunes.apple.com/rss" xmlns="http://www.w3.org/2005/Atom" xml:lang="en"> <id>https://itunes.apple.com/AU/rss/topalbums/limit=10/xml</id> <title>iTunes Store: Top Albums</title> <entry> <updated>2013-08-28T03:55:45-07:00</updated> <title>Paradise Valley - John Mayer</title> <im:releaseDate label="16 Aug 2013">2013-08-16T00:00:00-07:00</im:releaseDate> <im:itemCount>11</im:itemCount> </entry> <entry> <updated>2013-08-28T03:55:45-07:00</updated> <title>PRISM (Deluxe Version) - Katy Perry</title> <rights>℗ 2013 Capitol Records, LLC</rights> <im:releaseDate label="21 Oct 2013">2013-10-21T00:00:00-07:00</im:releaseDate> <im:itemCount>16</im:itemCount> </entry></feed>And I'd like the results for each row to return results like this:Title ReleaseDate Updated ItemCountParadise Valley - John Mayer 2013-08-28T03:55:45-07:00 2013-08-16T00:00:00-07:00 11PRISM (Deluxe Version) - Katy Perry 2013-08-28T03:55:45-07:00 2013-10-21T00:00:00-07:00 16Thanks!

Select in select subquery

$
0
0
I apologize for this not being specific to SQL 2012, but rather SQL in general, I ran into an issue with a statement that I expected would throw an error and yet it runs in an unexpected way. Basically the subquery should select a column that does not exist in the table referenced in it, yet it somehow runs. Below are the steps to reproduce:[font="System"]create table test1 (firstname1 varchar(10), lastname1 varchar(10))create table test2 (firstname2 varchar(10), lastname2 varchar(10))insert test1 values ('Larisa', 'Brown')insert test2 values ('John', 'Chaplan')select * from test1 where firstname1 in (select firstname1 from test2)[/font]Even though there is no column firstname1 in table test2, this query returns all rows in the table test1 and works as long as the subquery uses a column name defined in the first table and the second table is not empty. Prepending the proper table name to the subquery column (table2.firstname1) returns an error as expected, however why doesn't it return an error without it?

How to set out paramater when paging with t-sql and ROW_NUMBER()

$
0
0
Is there a way that I can set the output parameter when I've got my t-sql written the way that I do, and if now whats the recommendation?The ,@Total = COUNT(*) in the follow code does not work. How can I set the output parameter for paging?[code="sql"]USE [GenericCatalog]GO/****** Object: StoredProcedure [Generic].[proc_GetPartsForUserByCategory] Script Date: 8/27/2013 12:19:10 PM ******/SET ANSI_NULLS ONGOSET QUOTED_IDENTIFIER ONGOALTER proc [Generic].[proc_GetPartsForUserByCategory]@UserID UNIQUEIDENTIFIER,@GenericCatalogID INT,@CategoryID INT,@StartIndex INT, @PageSize INT, @Total INT OUTASSET NOCOUNT ON;SET @StartIndex = @StartIndex + 1BEGIN SELECT * FROM ( SELECT *, ROW_NUMBER() OVER (ORDER BY ID ASC) AS RowNum, COUNT(*) OVER() AS Total FROM ( SELECT p.*,gc.id'GenericCatalogID',@Total = COUNT(*), gc.SupplierName,gc.SupplierEmail,gc.SupplierPhone, pr.[Profile],pr.Siteline,pr.Depth FROM [Generic].[Part] p WITH(NOLOCK) JOIN Generic.UserPart up WITH(NOLOCK) ON up.PartID = p.ID JOIN Generic.GenericCatalog gc WITH(NOLOCK) ON gc.ID = up.GenericCatID JOIN Generic.[ProfileS] pr WITH(NOLOCK) ON p.ProfileID = pr.ID WHERE p.ID = up.PartID AND CategoryID = @CategoryID AND gc.UserID = @UserID AND gc.ID = @GenericCatalogID ) AS firstt ) AS final WHERE RowNum BETWEEN @StartIndex AND (@StartIndex + @pageSize) - 1 ORDER BY final.Number ASC;END; SET NOCOUNT OFF;[/code]

SQL Server 2012 Merge Replication - Delete operations on Merge Tables now require ALTER TRACE permisson due to Extended Stored Proceedure call master..sp_repl_generateevent. Some Advise would be appreciated

$
0
0
Hi All,In reference to http://dba.stackexchange.com/questions/29141/why-do-replication-deletes-require-sysadmin-accessI have the same issue as reported in the above link. The immediate issue has been bypassed in that I have granted ALTER TRACE permission to the main Applications account that does DELETE operations on the tables in question but in all honesty I don't want to grant that access just to bypass the error.Msg 8189, Level 14, State 10, Procedure sp_repl_generateevent, Line 1You do not have permission to run 'SP_TRACE_GENERATEEVENT'.Has anyone else ran into this and come up with a better solution other than biting the bullet and giving all accounts that run DELETE operations on the merge Tables ALTER TRACE permission?I could try some impersonation within the Replication Triggers to overcome this but of course if the replication is recreated then i would need to manually administrate the trigger code to manage the impersonation so that doesn't seem that practical to me.Does this mean that its now a requirement for all accounts that run delete operations on Merge replication Tables to have Alter Trace Permission? o.OSome advice would be greatly appreciated.Kind regards,Mattmc

Switch partition on Columnstore Index table

$
0
0
HiI understand that to update a Columnstore index table, one method is to switch to staging tables. I have a question, let say I need to switch 3 partition OUT at the same time (in order of Partition 1, Partition 2 and Partition 3), after update, am I able to switch the partition back in random order (eg: Partition 2, Partition 1 and Partition 3)?Thanks.

Help On Query

$
0
0
DECLARE @listStr VARCHAR(MAX)SELECT @listStr = COALESCE(@listStr+''''+',' ,'') + ''''+NameFROM sys.all_columns where object_id = object_id ('TableName')SELECT 'insert into tablename values ('+@listStr+''''+')'Could any one please explain how the above query works?

Find integer at end of a string. There *must* be a better solution ?

$
0
0
HiI want to find an integer after a hyphen in a string. If found, then use it. If not, then return -1This is the best I could figure out:[code="sql"]with tmp as ( select x = 'some text-1'union select x = 'some text-123'union select x = 'some text-123.4'union select x = 'some text 123'union select x = 'some text-'union select x = 'some text'union select x = 'some text-xyz')select * ,case when CHARINDEX('-',x) > 0 and LEN(x) > CHARINDEX('-',x) then iif(TRY_CONVERT(int, SUBSTRING(x,1 + CHARINDEX('-',x),LEN(x)-CHARINDEX('-',x))) IS NULL, -1, SUBSTRING(x,1 + CHARINDEX('-',x),LEN(x)-CHARINDEX('-',x)) ) else -1 end as result from tmp[/code]

How to Fatch last maximum non-zero values

$
0
0
Hi All ,I have a device table consists device reading data on the daily basis.The schema of the table is CREATE TABLE [dbo].[DeviceReading]( [ID] [int] IDENTITY(1,1) NOT NULL, [ReadNo] [int] NULL, [DeviceNo] [nvarchar](50) NULL, [DateCreated] [datetime] NULL) ON [PRIMARY]GOSample data is ID ReadNo DeviceNo DateCreated5 40 D1001 2013-08-29 23:37:41.5306 50 D1001 2013-08-29 23:37:41.5307 10 D1001 2013-08-29 23:38:07.0978 0 D1001 2013-08-29 23:38:07.0979 0 D1001 2013-08-29 23:38:07.09710 0 D1001 2013-08-29 23:38:07.09711 80 D1001 2013-08-29 23:38:07.09712 0 D1001 2013-08-29 23:38:07.09713 10 D1001 2013-08-29 23:41:31.99314 0 D1002 2013-08-29 23:41:31.99315 0 D1002 2013-08-29 23:41:31.99316 0 D1002 2013-08-29 23:41:31.99317 30 D1002 2013-08-29 23:41:31.99318 40 D1002 2013-08-29 23:41:31.993How do I get the Output - Last maximum non-zero value inserted in the table group by deviceNoD1001 = 80 D1002 = 40Please help !!!!Thanks Vineet Dubey

How to Split String

$
0
0
Good Morning Guys,Is There a simple way of splitting A Space Delimited String and putting it into 2 separate fields(e.G. Engine Make And Model ('PeterBilt MT2011')) the parameter would be coming from a Single field([b]Engine[/b]) from a table named[b] Units [/b]which i need to split to again insert to another tableso from EngineMakeAndModelPeterBilt MT20100ToEngineMake Model[b]Peterbild MT2100[/b]and is it possible for this not to be put into a UDF?Best Regards,Noel

T-SQL Pvot Data and Hide duplicates

$
0
0
I need help in pivoting comments columns to show data in parallel belowTable 1Camry_Id,Month,Year,Dealer,Camry_Comments,1,7,2013,Hendrick,Camry Comment 1,2,7,2013,Hendrick,Camry Comment 2,3,7,2013,Hendrick,Camry Comment 3,4,7,2013,AutoCity,Camry Comment 4,5,7,2013,AutoCity,Camry Comment 5,6,7,2013,Leith,Camry Comment 6,7,8,2013,Leith,Camry Comment 8,8,8,2013,Leith,Camry Comment 9,Table 2Corolla_Id,Month,Year,Dealer,Corolla_Comments,1,7,2013,AutoCity,Corolla Comment 1,2,7,2013,AutoCity,Corolla Comment 2,3,7,2013,AutoCity,Corolla Comment 6,4,7,2013,Leith,Corolla Comment 3,4,7,2013,Leith,Corolla Comment 8,6,8,2013,Leith,Corolla Comment 4,8,7,2013,Hendrick,Corolla Comment 7,Result,Month,Year,Dealer,Camry_Comments,Corolla_Comments,7,2013,AutoCity,Camry Comment 4,Corolla Comment 1,7,2013,AutoCity,Camry Comment 5,Corolla Comment 2,7,2013,AutoCity,,Corolla Comment 7,7,2013,Hendrick,Camry Comment 1,Corolla Comment 7,7,2013,Hendrick,Camry Comment 2,,7,2013,Hendrick,Camry Comment 3,,7,2013,Leith,Camry Comment 6,,7,2013,Leith,,Corolla Comment 8,8,2013,Leith,Camry Comment 8,Corolla Comment 4,8,2013,Leith,Camry Comment 9,Essentially I want to join on month, year and Dealer and display comments in each column aligned. Soif there are comments from both then show both on same likeIf one has 2 and other has 1 show first ones on same line; second on next line.Hide duplicates.It has to show all records(full outer join) from both tables with not multiply or duplicates on either corolla or camry comments column

Trying to understand Cross Apply

$
0
0
I wrote this query, which runs nicely (under 1 second) and returns 4490 rows:[code="sql"]select distinct t1.id, t1.phonenumber, u.phone as [Universe Match] , s.phone as [Specialty Practice Match] , p.phone as [Primary Care Match] , case when t1.orc_cell1 = 7 then 'Customer' when t1.orc_cell1 = 9 then 'Non-Customer' else null end as [Designation]from j3689141 as t1 left join J3689141_IDNCHK as u on t1.phonenumber = u.phone left join J3689141_IDNCHK2 as s on t1.phonenumber = s.phone left join J3689141_IDNCHK3 as p on t1.phonenumber = p.phonewhere (u.phone is not null or s.phone is not null or p.phone is not null) and t1.orc_cell1 in (7, 9) and t1.statusflag = 0order by t1.id[/code]After that I was a little bored, and since I still don't totally understand cross apply, I tried writing it like this:[code="sql"]select distinct t1.id, t1.phonenumber, u.phone as [Universe Match] , s.phone as [Specialty Practice Match] , p.phone as [Primary Care Match] , case when t1.orc_cell1 = 7 then 'Customer' when t1.orc_cell1 = 9 then 'Non-Customer' else null end as [Designation]from j3689141 t1 cross apply ( select u.phone from j3689141_IDNCHK u where t1.phonenumber = u.phone ) as u cross apply ( select s.phone from j3689141_IDNCHK2 s where t1.phonenumber = s.phone ) as s cross apply ( select p.phone from j3689141_IDNCHK3 p where t1.phonenumber = p.phone ) as pwhere (u.phone is not null or s.phone is not null or p.phone is not null) and t1.orc_cell1 in (7, 9) and t1.statusflag = 0order by t1.id[/code]Which runs, but only returns one row, though not incorrectly (just 4489 rows short). Where did I go wrong? Am I using cross apply in the wrong place? I feel like I've read dozens of articles about it, but something isn't clicking.Thanks
Viewing all 4901 articles
Browse latest View live