I need to manipulate some sets, doing joins based on intersection, and looking for subsets. Is there any way to store an array in a single data field? And then do operations based on those array lists? e.g. -
{1,2,3} intersect {2,3,4} ==> {2,4} (would like to then be able to do joins based on intersection, so that I could say, return all cases where two sets have all but one member from each in common...)
I'm new to MDX and was hoping someone could answer this question. I'm working on an MDX query, a simplified version is below.
What I'm trying to do is to pull 2 sets, based on a date range. Based on those, I'd like to see the total "cost" measure for each set, and divide one by another.
What I'm finding is that when I run the query below, the cost is broken out by month. So, my select statement gives me the cost for January 2008 and February 2008 in the CurrentPeriod set, and for January, February, etc. 2007 in the PriorPeriodData set. What I want instead is to get the total "cost" measure for all the months in each set. I believe this is what I'd get if I put the date range in a subcube or a where clause - but in that case, I wouldn't be working with 2 distinct sets.
Is there some other way to write this, or to combine all the months in the set before the measures?
I had a view in which I did something like this isnull(fld,val) as 'alias'
when I assign a value to this in the client (vb 6.0) it works ok in sql2000 but fails in 2005. When I change the query to fld as 'alias' then it works ok in sql 2005 . why ?? I still have sql 2000 (8.0) compatability.
Also some queries which are pretty badly written run on sql 2000 but dont run at all in sql 2005 ???
any clues or answers ?? it is some configuration issue ?
PLEASE SEE my update (post #3) for a better simpler explanation!!!!!
Hi, I need a query which is basically
(query 1) Except (query 2)
SQL server supports (query 1)Union (query 2) but I can't get the Except to work.
Alternatively, I also tried to implement it by using the "NOT IN" but didnt work. Background: 3 tables, accnts, Opty, Opty_postn I want the accounts who have 1 or more opty's at 100% (sold) before 1/1/2002 but zero opty's at 100% after 12/31/2001. accnts has fields ID & name, ROW_ID opty has fields acct_id, prob, ROW_ID opty_postn has fields opty_id, close_dt
My query: SELECT accnt.name FROM accnt WHERE accnt.ROW_ID IN ( SELECT acct_id FROM opty where prob = 100 AND opty.ROW_ID IN (SELECT opty_id FROM opty_postn WHERE close_dt<1/1/2002) ) AND accnt.ROW_ID NOT IN ( SELECT acct_id FROM opty where prob = 100 AND opty.ROW_ID IN (SELECT opty_id FROM opty_postn WHERE close_dt >12/31/2001) ) AND accnt.ROW_ID = opty.accnt_ID
my intent was select account.names where id is in set(prob = 100 & sale before 1/1/02) but not in ( prob = 100 & sale after 21/31/01) SO ,the accounts which have sales both before and after get counted. But I want only those accoutns which have sales only before 1/1/02. I hope i explained this right. Thanks in advance for your help.
Hi,I've tried without success to create a function where one of theparameters determines the final line of a select statement.The final line includes a 'where referencenumber in (@set)' line.. and@set is the parameter I wish to use which is a string.If the set is just one value, it works fine, however with anything morethan that I just get no records returned.. If I output the parameter,and copy and paste that into query analyser I do get the correct result,so it's nothing to do with string delimiters etc..Any ideas to fix this problem? Or am I going to have to dynamic sql thewhole thing?Cheers,Chris
Hi, I'm currently trying to retrieve results from a large dataset, there are over 45000 records and I need to use them all to peform counts etc. I have set up views, but my page is still being returned slowly, is there anything I can do to speed this up? Thanks Gemma
I am trying to query one table and get two different timeperiods of data, I am summing monthly totals to provide a running year total, but I also need last month's total in a seperate column. This is what I have so far but the subquery makes me group it which provides duplicate grouping.DECLARE @LASTPD AS INT SET @LASTPD = (SELECT MAX(LASTPERIOD) FROM TABLE) SELECT NAME, POST_PD AS [MONTH],SUM(CHARGE_AMOUNT) AS MONTHLY_$, LASTMONTH.LAST_MONTH,(SELECT SUM(CHARGE_AMOUNT) AS LAST_MONTH FROM TABLE INNER JOIN TABLE2 ON TABLE2.NAME = TABLE.NAME WHERE POST_PD = @LASTPD AND TABLE2.NUM= 539 GROUP BY NAME) AS LASTMONTH INTO #TEMP_SAFROM TABLE INNER JOIN TABLE2 ON TABLE2.NAME = TABLE.NAME,(SELECT SUM(CHARGE_AMOUNT) AS LAST_MONTH FROM TABLEWHERE TABLE2.NUM = 539 GROUP BY NAME, POST_PDORDER BY NAME, POST_PD SELECT NAME, LAST_MONTH, CAST(SUM(MONTHLY_$)AS DECIMAL(20,2)) AS YEARLY_$ FROM #TEMP_SA GROUP BY NAME ORDER BY NAME
I need to upgrade a 6.5 box to 7.0 but also change the character sets. Let me know how this sounds.
-Have a 2nd machine w/ 6.5 on it and same char sets. -backup/restore data from prod box to 2nd machine. -upgrade 2nd machine to 7.0 using the same char sets. -uninstall prod machine and install 7.0 w/ new char set. -use dts to move data from 2nd machine to new machine. (changing char sets from old to new)
We're constructing a three-tier application. We want the middle tier to extract a recordset from the database, disconnect from the database, then pass the recordset to the front tier. After changes have been made by the front tier, it will pass the recordset back to the middle tier, which will reconnect, and update the database. The problem: Using stored procedures, the recordset is no longer available once the connection has been closed. Is there any way, using stored procedures, to be able to keep the recordset available after the connection has been closed, either by preserving it, copying it, or otherwise?
they are not necessary mutual exclusive. thus, union is not good. However, when I use derived table method, I will have 'dups' on column of 'Region' and 'county', 2 total are fine.
I have been tasked with creating a report that shows sales of our products grouped into buckets of 5 each, DESC. I have a table that has the itemNo and revenue. The final report would be something like:
Top 5 Spreads$695,066 Next 5 Spreads$467,845 Next 5 Spreads$416,946 Next 5 Spreads$361,946 Next 5 Spreads$305,607 Next 5 Spreads$270,567 Bottom Spreads$15,954
My initial thinking was to use row_number() and partition to label the rows in groups of 5 like:
i have these 2 queries with the included results sets...What commands could I use to take the TotalBlueCircle Column from the 2nd Results Set and have it included next to the TotalRugby column in the 1st results set??Do i need to do a UNION or use Sub Queries or something else?
I have a maintenance plan setup to expire backup sets after 4 days, but its keep backup copies for an infinite amount of time. I might be misunderstanding whats suppose to happen, but I would expect the files to be removed after 4 days.
I would like to match two sets of data. I have setup a view of data that contains a group of customers and their details. I want to view this data, but also find these customers in another table based on matching their surname and date of birth, then retreive the information stored on these customers from the second table.
Does anyone have any suggestions how i would go about doing this?
Thanks in advance Humate
quote:Originally posted by Michael Valentine Jones
It takes real skill to produce something good out of a giant mess.
I have the following situation. One set of data has 274 rows (set2)and anther has 264 (set1). Both data sets are similar in structure aswell as values for both of them were extracts from the same parenttable. Hope the info would substitute DDL. I need to find the "gap"rows between these two sets.Attempted to run a query likeselect count(*)from set2where not exists(select *from set1)did not yield what I desired. What else to try?TIA.
Hello!My client has a need to be able to store Japanese characters in theirPeopleSoft database. So we need to change the character set from fromLatin1_General (1252) to Japanese character set (932) on SQL Server2000 Enterprise. I have 2 questions:1) I would like to know if in SQL Server, the character set is machinespecific or is it defined at the database instance level?2) Can multiple installs of SQL Server co-exist on a single server withdifferent default character sets?ThanksVishal
Hi!Another silly question:If a stored procedure returns multiple result sets, how do I choose the oneI want to insert into a table?For example sp_spaceused returns two result sets if object name is ommited.I only need the first result set. How do I do that?Tnx!Darko
Hi, I'm trying to return 2 different result sets using the below query mapped to 2 different variables in my execute sql task. I've tried this with one task and 2 seperate tasks but can't get it to work. Is this possible using only one task? It keeps giving me a result set error.
SELECT COUNT(*) AS DeceasedCount FROM AMGR_User_Fields_Tbl WHERE (Client_Id = '' or Client_Id is NULL) and Type_Id = 53
SELECT COUNT(*) AS LostCount FROM AMGR_User_Fields_Tbl WHERE (Client_Id = '' or Client_Id is NULL) and Type_Id = 469
I was working on what I was told was SQL 2012 and it turns out it is SQL 2005. I wrote two procs that I need to convert to 2005. Here is the code:
SELECT era_provider_name AS Provider, RIGHT([era_upi], 5) AS 'ERA Upi', [era_fy] AS 'ERA FY', ProcGrp, COUNT(DISTINCT UCI) AS 'Client Count',
[Code]....
I'm not finding an efficient way to do this. I cannot use GROUPING SETS with 2005. Here is the code for the second proc:
SELECT CASE WHEN GROUPING(era_provider_name) = 1 THEN 'TOTALS' ELSE era_provider_name END AS era_provider_name, CASE WHEN GROUPING(era_fy) = 1 THEN 'TOTALFY'
[Code] ...
The results as in SQL 2012 are exactly as I would like them. I want to mimic those results in 2005.
I popped into the Transact-SQL forum to get some help and created the dbo.selectaudit1 table, which can be queried succesfully.
Code Blockcreate table dbo.selectaudit1 (startkey varchar(10) not null, endvalue varchar(10) null, endkey as coalesce(endvalue, startkey))
insert into dbo.selectaudit1 (startkey) select '042' union all select '140' union all select '2089' union all select '2031' union all select '2051' union all select '2100' union all select '2299' union all select '2300' union all select '2349' union all select '2350' union all select '2389' union all select '2390' union all select '2399' union all select '2732' union all select '2733' union all select '2849' union all select '2850' union all select '2883' union all select '2898' union all select 'V073' union all select 'V078' union all select 'V100' union all select 'V109' union all select 'V580' union all select 'V581' union all select 'V661' union all select 'V662' union all select 'V671' union all select 'V672' union all select 'V711' union all select 'V760' union all select 'V769' insert into dbo.selectaudit1 (startkey, endvalue) select '1400' ,'2089' union all select '2100', '2299' union all select '2300' ,'2349' union all select '2350' ,'2389' union all select '2390' ,'2399' union all select 'V100' ,'V109' union all select 'V760' ,'V769'
Then in reporting services, I created a report with the following query in my dataset. This query works fine in a BIDS query windows, however, when I refresh my dataset and attempt to execute the query I am getting the following error:
Cannot find the object "selectaudit1" because it does not exist or you do not have permissions. (Microsoft SQL Server, Error: 1088)
Code Block Select p.MRN , p.PatientName , CONVERT(CHAR(20),p.AdmitDate,101) AS AdmitDate , CONVERT(CHAR(20),p.DischDate,101) AS DischDate , p.VisitTypeCode , d.VisitTypeName , p.AnyDx , p.PrinDxCode , p.PrinDxDesc , p.SecDx1Code , p.SecDx2Code , p.SecDx3Code , p.SecDx4Code , p.SecDx5Code , p.SecDx6Code , p.SecDx7Code , p.SecDx8Code , p.SecDx9Code , p.SecDx10Code , p.SecDx11Code , p.SecDx12Code , p.SecDx13Code , p.SecDx14Code , p.SecDx15Code From dbo.PtMstr p inner join ampfm.dct_VisitType d on d.VisitTypeCode=p.VisitTypeCode INNER JOIN dbo.selectaudit1 sel ON (PrinDxCode between sel.startkey and sel.endkey AND DischDate between '2006-11-01' and '2007-09-30') OR (SecDx1Code between sel.startkey and sel.endkey AND DischDate between '2006-11-01' and '2007-09-30')
I am aware that SSRS does not support stored procedures with multiple data sets, but what if the same stored procedure may only return one set based on a parameter?
For example, lets say if parameter @TableID = 0, the stored procedure returns 2 result sets. But if @TableID = 1, or @TableID = 2, the SP only brings back 1 result set. Is this also not supported?
When I try to do this it still only brings back the fields from the first table. Am I doing something wrong?
What is the recommended mechanism for selecting paged results from SQL.
Presently I pass various params including the request Max Items Per Page and the requested page.
The I execute the query as a count with the search params.
Then comes the paging logic, which validates the page number against the request page and number of hits etc.
Then a temp table and record variables are created for the results.
Then I run the query again with a cursor and select the appropriate Items into the temp table based on the paging values (First Item and Last Item).
Then I return the temp table & some additional return params with the Total Hits etc.
The Stored procedure is accessed via an ADO.Net client and the system.data.IDBReader populates a .Net strongly typed collection and is for read only display.
My stored procedure displays two result sets. How can i use that result sets in my 3-tier application. I want to bind first resultset to repeater control and second to label control. I am using SqlDataReader...
Supposing I have a sort order/char set installed and some databases working under these circumstances.Is there any way to change order and sets without losing my old databases? If I try to rebuild databases, I lose them,and when i try to restore them, there's a conflict between the new SQL Server 6.5 configuration and the Databases previously created in old sort order/char sets?Is there any solution to this,or once I have chosen the database configurations,I'll have to either recreate the data or die with them??? Neede answers ASAP....
I have a need to store records in two different languages. Has anyone done this and what were the requirements. Can you do this within the same database, table?
Hi folks. Hope all the gurus including Brett,Pat Phalen, RdjBarov, r937 are fine. ;) been so long to ask stupid question. Here's the question and i really need help on this.
i have data that tracks patterns of bus stops from one point to another. like point a, to point b, point b to point c forms one pattern. point a to point c , point c to point b should be a different pattern.
create table #journeypatterns (patternid int ,points varchar(100)) go insert #journeypatterns select 1 ,'a' union all select 1 ,'b' union all select 1,'c' union all select 2,'a' union all select 2,'c' union all select 2,'b' union all select 3 ,'a' union all select 3 ,'b' union all select 3,'c'
select * from #journeypatterns
patternid points 1 a 1 b 1 c 2 a 2 c 2 b 3 a 3 b 3 c
what i want is to get unique pattern value of sequence of points by grouping on patternid. if the sequence of points change, i need a unique value against that pattern. like for patternid 1, sequence of points a,bc for example should be abc. for patternid 2, sequence of points a,c,b for example should be acb. again patternid 3, sequence of points a,bc for example should be abc.
i tried CHECKSUM_AGG which brutally failed in production because the checksum values for each single point when summed produce SAME result for different patterns.
select checksum_agg(binary_checksum(points)) ,patternid from #journeypatterns group by patternid
961 962 963
here patternid 2 should be different because sequence is acb. i know checksum is not the right approach for what i need.
I NEED A GENERIC FUNCTION, that marks the pattern differences, my ultimate goal was to create a procedure, whom a patternid should be passed, and it would result the NEXT patternid in the table which has the SAME ORDER OF point sequences.
now folks, i can do this holding all data into a temp table and write a cursor to traverse through each patternid and concatenate the sequence of points. BUT, using this approach is the ugliest, as it has slow down the process badly and boss is not happy with the performance. the table holds a lot of data. I NEED a query rather than a cursor on the fly to resolve this. Here's the query i am using to get the current sequence of a pattern and then i have to search all sequences similarly against it.
declare @patternid int set @patternid =1 declare @sequence [varchar] (100) declare @id varchar(10) declare cr_sequence cursor fast_forward for select points from #journeypatterns where patternid=@patternid open cr_sequence fetch next from cr_sequence into @id while @@fetch_status = 0 begin select @sequence = isnull(@sequence,'')+@id fetch next from cr_sequence into @id end print @sequence -- next i have code to find the similar sequence for another patternid.... which is not mentioned here but is similar
Code: SELECT DISTINCT LEFT([REPORTING_MONTH], 4)+'-'+SUBSTRING([REPORTING_MONTH],5,6) as REPORTING_MONTH, t.EMPLOYEE, '' as COUNT_FTP, CASE WHEN [MEDIUM_RCVD] = 'EMAIL' THEN COUNT(MEDIUM_RCVD) ELSE '' END AS COUNT_EMAIL FROM [GPO].[dbo].[DW_SUBMISSION] as s JOIN #TEMPActivity as t
[Code] ....
I'm trying to get the set to come out all on one line. REPORTING_MONTH, EMPLOYEE, COUNT_FTP, COUNT_EMAIL
But when I try null or '' it creates a second record and doesn't merge the two results.
I have two tables - one with sales and another with payments against those. The payment may not match the exact amount of sales and I have to use FIFO method to apply payments. The payment month must >= sales month.
How can i write a query to do this? Examples are as below.
Table 1 Sales Sale DateSale Amt 1Jun-141200 2Oct-142400 3Dec-14600 4Feb-1512000