I've set up a transactional replication, but I need to specify in which order the tables are to be replicated (tables with foreign keys last).
How/where do set table order ?
I never paid much attention to this before but I noticed this today in a new table I was creating.
For tables defined in the tabular model the table properties have something like SELECT Blah FROM TableName ORDER BY Blah Then in the tabular model the table's data is in the same order it was ordered by in the data source for the table.
I have a date table I setup and I noticed it is NOT respecting the sort order.
I have it sorted by DateID which sorts with the oldest date first and newest date as last row.However, the table that is imported and stored in the data model is not in that order.
I can of course manually sort the rows in BIDS/DataTools, but I find this discrepancy odd.
Would this have negative impacts on the EARLIER function for example if the data rows are not in the order specified?
Hi, this is a repost from the SQL Server group.I am wondering if it is possible to change the order that articles arepropagated to the subscriber. I currently have a table, say table Athat is used in view B. However, for a variety of reasons I need tochange the name of the table to C and create a new view called A.However, view B is being replicated before view A is being replicatedand it is generating an error, "The script file for view B cannot bepropagated to the subscriber."I'm hoping that by replicating view A first I should be able to avoidthe error.Any help would be appreciated. I hope my explaination is clear enough.Thanks,Cameron
Question re Merge rep (pull) and processing order. We have a group of changes associated with an app upgrade, the scripts run fine on the publisher. Part of the change includes creation of a new table , followed by altering a view to use new table.Following the change at the publisher, when the sync is kicked off from the subscriber, it fails - the alter of the view throws an'invalid object' error with regard to the new table. Seems as if the view alter is attempted before the dependant table has been created.
I have tried to amend the processing order of the view using sp_changearticle, which executes (quickly) with a 0 return code.But it is to no avail , the error still occurs. is it possible to change the processing order for a view article , which will be applied to schema changes ? Have
I have 2 tables: Order(ID, Quantity) and Product(ID,Name, Price) and I want to add a calculated field in Order table based on the price column in the Product table. How do i do that?
this query returns the values i want in the table.
select a.quantity * b.price from tblCustomerPurchases as a join tblProduct as b on a.ID=b.ID
In my production box is running on SQL7.0 with Merge replication and i want add one more table and i want add one more column existing replication table. Any body guide me how to add .This is very urgent Regards Don
I noticed that some queries against an mssql db require the tables in the FROM part of the statement to be in a particular order. Does anyone know why?
For example SELECT * FROM table1, table2, table3 WHERE <blah>
May throw an error (Unknown table table3 [I can't remember the exact verbiage of the error]), while simply rearranging the table order to:
SELECT * FROM table3, table1, table2 WHERE <blah> will work.
It seems like the error has something to do with how mssql handles the joins of the tables, but I can't seem to find any documentation about it.
merchant contractbr date a 2333 1/1/2005 a A34 3/12/2006 a R78 2/1/2005 .. b b b c c c .....
different merchant has different number of contracts. I want to order the contracts for merchants according to the date. the result table should look like:
merchant contractbr date order a 2333 1/1/2005 1 a R78 2/1/2005 2 a A34 3/12/2006 3 .. b 1 b 2 b 3 c 1 c 2 c 3 c 4 c 5 .....
Greetings,I have an application that need to get all the userdefined child tables first before their parents.I wrote a query, given in this newsgroup only, as belowSELECT o.nameFROM sysobjects oWHERE o.type='U'ORDER BY case WHEN exists ( SELECT *FROM sysforeignkeys fWHERE o.id = f.fkeyid )THEN 1ELSE 0end, o.namegoWhen i try to truncate the first table of the list, it still tells methat tha table is being referenced by foreign key in another table. Mymain job is to truncate all the user defined tables before loading datainto them.Is there something wrong in the query? Or if someone can tell me abetter approach.Any help will be appreciated.TIA
Hello everyone,I am involved in a scenario where there is a huge (SQL Server 2005)production database containing tables that are updated multiple timesper second. End-user reports need to be generated against the data inthis database, and so the powers-that-be came to the conclusion that areporting database is necessary in order to offload report processingfrom production; of course, this means that data will have to bereplicated to the reporting database. However, we do not need all ofthe data in the production database, and perhaps a filtering criteriacan be established where only certain rows are replicated over to thereporting database as they're inserted (and possibly updated/deleted).The current though process is that the programmers designing thequeries/reports will know exactly what data they need from productionand be able to modify the replication criteria as needed. For example,programmer A might write a report where the data he needs can beexpressed in a simple replication criteria for table T where column X= "WOOD" and column Y = "MAHOGANY". Programmer B might come along amonth later and write a report whose relies on the same table T wherecolumn X = "METAL" and column Z in (12, 24, 36). Programmer B willhave to modify Programmer A's replication criteria in such a way as toaccomodate both reports, in this case something like "Copy rows fromtable T where (col X = "WOOD" and col Y = "MAHOGANY") or (col X ="METAL" and col Z in (12, 24, 36))". The example I gave is reallytrivial of course but is sufficient to give you an idea of what thecurrent thought-process is.I assume that this is a requirement that many of you may haveencountered in the past and I am wondering what solutions you wereable to come up with. Personally, I believe that the above method isprone to error (in this case the use of triggers to specifyreplication criteria) and I'd much rather use replication services tocopy tables in their entirety. However, this does not seem to be anoption in my case due to the sheer size of certain tables. Is thereanything out there that performs replication based on complexprogrammer defined criteria? Are triggers a viable alternative? Anyalternative out-of-the-box solutions?Any feedback would be appreciated.Regards!Anthony
When I say to sort on a datetime field on descending order, the date is sorted. However, the time difference is not reflected in the results. Any way, we can fix it. i.e. If I have two records with the same dates but different times, the sorting order is not considering the time.
For example some data has entered into a table in a random manner i.e the pk filed value is not in a serial fashion.Is there any table or index that holds the entries of rows into a particular table as entered .
i.e 'some_table' has data like this
3,entry3 2,entry2 4,entry4 1,entry1
I want some DB table or Index that holds data like this about above 'some_table'
row_id .... .... .... 1 2 3 4
here 1 refers to entry of the first column in 'some_table' i.e 3,entry3 and so on...
I have one query with 3 statments in it, which then creates a table called HCSReturnFile. My problem is that I have an order by in my query, but when I go to create a table that puts all 2 statements into 1, it does not do the order by. What am I doing wrong? Below is my Query.
USE [Impact_PROD] GO /****** Object: StoredProcedure [dbo].[p_GenerateHCSReturnFileUPDATE] Script Date: 01/18/2008 14:20:59 ******/ SET ANSI_NULLS ON GO SET QUOTED_IDENTIFIER ON GO -- ============================================= -- Author:Wendy & Mike -- Create date: 11/08/2007 ---Create Date to Production - 12-06-2007 -- Description:This was a touch one. ---This report drop both Queries into a tabled called HCSRetrunFile -- ============================================= ALTER PROCEDURE [dbo].[p_GenerateHCSReturnFileUPDATE]
AS BEGIN -- SET NOCOUNT ON added to prevent extra result sets from -- interfering with SELECT statements. SET NOCOUNT ON; IF OBJECT_ID('IMPACT_PROD..HCSReturnFile') IS NOT NULL DROP TABLE HCSReturnFile
INSERT INTO [IMPACT_PROD].[dbo].[HCSReturnFile] ([EventNumber] ,[ClaimNumber1] ,[Resolution] ,[Resolution2] ,[ProviderType] ,[Negotiation] ,[NEGOYESORNO] ,[ProviderID] ,[HCSAuthorizationID] ,[PROLASTNAME] ,[proFirstName] ,[ProOffice] ,[TOTALBILLEDAMT] ,[SAVINGS] ,[OONNEGO] ,[CLM_ATT1] ,[CLM_ATT2] ,[CLM_ATT3] ,[CLM_ATT4] ,[CLM_ATT5] ,[NoteData]) SELECT Distinct --n.note_sys, --c.CLM_id1 AS 'ClaimNumber', e.EVE_id1 AS 'EventNumber', ClaimNumber1 = '', --e.EVE_clm As 'EventEventTable', --c.CLM_elrc AS 'EventClaimTable', e.eve_resl1 as 'Resolution', p.EVEP_RESL1 as 'Resolution2', p.evep_reas as 'ProviderType', p.evep_nego as 'Negotiation', --e.EVE_STAT AS 'STATUS', e.EVE_SW01 AS 'NEGOYESORNO', ProviderID = '', e.EVE_EXNO AS 'HCSAuthorizationID',
--p.EVEP_LNAME AS 'PROVIDERLASTNAME', --p.EVEP_FNAME AS 'PROVIDERFIRSTNAME', p.EVEP_LNAME AS PROLASTNAME, p.evep_fname AS proFirstName, p.evep_offic AS ProOffice, --c.CLM_EDID AS 'LOCKDATE', TOTALBILLEDAMT = '', SAVINGS = '', OONNEGO = '', c.CLM_ATT1, c.CLM_ATT2, c.CLM_ATT3, c.CLM_ATT4, c.CLM_ATT5, n.NoteData
FROM dbo.EVE e
RIGHT JOIN dbo.clm c ON e.EVE_id1 = c.clm_id1 RIGHT JOIN dbo.EVEP p ON e.eve_id1 = p.EVEP_id1 JOIN dbo.notes2 n ON n.eve_id1 = e.EVE_id1 --JOIN evep p2 --ON p.evep_id1 = p2.evep_id1
Where e.eve_resl1 = 'CL'and p.EVEP_RESL1 <> 'NG' and p.evep_reas <>'FA'--and ---means closes Events --p2.evep_nego = 'Y' and --((LTRIM(p.evep_id2) <> '0002' AND p.evep_id2 <> '0001' AND p2.evep_id2 <> '0001') OR (SELECT COUNT(*) FROM evep WhERE evep_id1 = p.evep_id1) = 1) --e.EVE_STAT = 'CL'and --e.EVE_id1 IN ('00101965','00102080','00102084','00101962','00101963') --and
SELECT Distinct --n.note_sys, --c.CLM_id1 AS 'ClaimNumber', e.EVE_id1 AS 'EventNumber', ClaimNumber1 = '', --e.EVE_clm As 'EventEventTable', --c.CLM_elrc AS 'EventClaimTable', e.eve_resl1 as 'Resolution', p.EVEP_RESL1 as 'Resolution2', p.evep_reas as 'ProviderType', p.evep_nego as 'Negotiation', --e.EVE_STAT AS 'STATUS', e.EVE_SW01 AS 'NEGOYESORNO', ProviderID = '', e.EVE_EXNO AS 'HCSAuthorizationID',
--p.EVEP_LNAME AS 'PROVIDERLASTNAME', --p.EVEP_FNAME AS 'PROVIDERFIRSTNAME', p.EVEP_LNAME AS PROLASTNAME, p.evep_fname AS proFirstName, p.evep_offic AS ProOffice, --c.CLM_EDID AS 'LOCKDATE', TOTALBILLEDAMT = '', SAVINGS = '', OONNEGO = '', c.CLM_ATT1, c.CLM_ATT2, c.CLM_ATT3, c.CLM_ATT4, c.CLM_ATT5, n.NoteData
FROM dbo.EVE e
RIGHT JOIN dbo.clm c ON e.EVE_id1 = c.clm_id1 RIGHT JOIN dbo.EVEP p ON e.eve_id1 = p.EVEP_id1 JOIN dbo.notes2 n ON n.eve_id1 = e.EVE_id1 --JOIN evep p2 --ON p.evep_id1 = p2.evep_id1
Where ((e.eve_resl1 = '' and p.evep_reas = 'HO')or (e.eve_resl1 = '' and p.evep_reas = 'PH') or (e.eve_resl1 = '' and p.evep_reas = 'AN'))
Order by e.eve_resl1,p.EVEP_RESL1
--and ---means Open Events will not have claims attached to them. we just need the fields in this report. --p2.evep_nego = 'Y' and --((LTRIM(p.evep_id2) <> '0002' AND p2.evep_id2 <> '0001') OR (SELECT COUNT(*) FROM evep WhERE evep_id1 = p.evep_id1) = 1)
INSERT INTO [IMPACT_PROD].[dbo].[HCSReturnFile] ([EventNumber] ,[ClaimNumber1] ,[Resolution] ,[Resolution2] ,[ProviderType] ,[Negotiation] ,[NEGOYESORNO] ,[ProviderID] ,[HCSAuthorizationID] ,[PROLASTNAME] ,[proFirstName] ,[ProOffice] ,[TOTALBILLEDAMT] ,[SAVINGS] ,[OONNEGO] ,[CLM_ATT1] ,[CLM_ATT2] ,[CLM_ATT3] ,[CLM_ATT4] ,[CLM_ATT5] ,[NoteData]) SELECT Distinct c.CLM_elrc AS 'EventNumber', CASE c.clm_ips WHEN 'C' THEN c.clm_pclm ELSE c.clm_id1 END as "claimnumber1", --ClmClaims."CLAIMNUMBER", --c.CLM_PCLM as "CLAIMNUMBER", --n.note_sys, --c.clm_id1, --e.EVE_clm As 'EventEventTable', e.eve_resl1 as 'Resolution', p.EVEP_RESL1 as 'Resolution2', p.evep_reas as 'ProviderType', p.evep_nego as 'Negotiation', --e.EVE_STAT AS 'STATUS', e.EVE_SW01 AS 'NEGOYESORNO', c.CLM_5 AS 'ProviderID', e.EVE_EXNO AS 'HCSAuthorizationID', --p.EVEP_LNAME AS 'PROVIDERLASTNAME', --p.EVEP_FNAME AS 'PROVIDERFIRSTNAME', --p.EVEP_OFFIC AS 'PROVIDEROFFICE', p.evep_lname AS ProLastName, p.evep_fname AS proFirstName, p.evep_offic AS ProOffice, c.CLM_MCHG AS 'TOTALBILLEDAMT', c.CLM_SPPO AS 'SAVINGS', c.CLM_55d AS 'OONNEGO', c.CLM_ATT1, c.CLM_ATT2, c.CLM_ATT3, c.CLM_ATT4, c.CLM_ATT5, n.NoteData
FROM dbo.EVE e Right Join dbo.clm c ON e.EVE_id1 = c.clm_elrc Right join dbo.EVEP p ON e.eve_id1 = p.EVEP_id1 --JOIN evep p2 --ON p.evep_id1 = p2.evep_id1 JOIN dbo.notes2 n ON n.eve_id1 = e.EVE_id1
Where p.EVEP_RESL1 = 'NG'and clm_adjto = '' ---"NG"This report is going to be changed to the negoitated report the field is going to be "NG" --e.eve_resl1 = 'NG'and --p2.evep_nego = 'Y' and --((LTRIM(p.evep_id2) <> '0002' AND p.evep_id2 <> '0001'AND p2.evep_id2 <> '0001') OR (SELECT COUNT(*) FROM evep WhERE evep_id1 = p.evep_id1) = 1)
I have a table that I want to re-order the ID column. The ID are not in order now due to some insertion and deletion. What are the steps to re-order the ID column?
SELECT ID,new_unit,mhlka_id,mhlka, DATEPART(DAY, Date) AS theDay, ShiftID FROM v_Employee WHERE Date >= @BaseDate AND Date < DATEADD(MONTH, 1, @BaseDate)
ORDER BY unit desc, Fname
) AS y PIVOT ( min(y.ShiftID) FOR y.theDay IN ([1], [2], [3], [4], [5], [6], [7],[8] , [9], [10], [11], [12], [13], [14], [15], [16], [17], [18], [19], [20], [21], [22], [23], [24], [25], [26], [27], [28], [29], [30]) ) AS p END
the all code
DECLARE @Employee TABLE (ID INT, Date SMALLDATETIME, ShiftID TINYINT)
DECLARE @WantedDate SMALLDATETIME, -- Should be a parameter for SP
@BaseDate SMALLDATETIME,
@NumDays TINYINT
SELECT @WantedDate = '20080401', -- User supplied parameter value
I have nested lists and I want to set a global value in my custom code AFTER a specific table footer row. Does anybody know in what order the table elements are rendered? I have tried adding my piece of code into a group value, the hidden property, the color property, and sending it as a parameter to a subreport, but it still sets that variable first before rendering the table footer row that I want to display before I set that variable. I have been pulling my hair out trying to do this one! Help!
how to order by month name query returns Dec13,Mar14,Jan14,Nov13 .. etc but i want to Nov13,Dec13,Jan14,Mar14 ... etc
declare @cols as varchar(max), @query as varchar(max) set @cols =STUFF((select ','+QUOTENAME(tb3.month) FROM ( select distinct (DATENAME(MONTH,dtDate)+''+CONVERT(varchar(5),YEAR(dtDate)) ) as month from tableA) tb3 FOR XML PATH(''), TYPE ).value('.','NVARCHAR(MAX)'),1,1,'') set @query ='SELECT '+@cols +' from (SELECT DATENAME(MONTH,dtDate) + CONVERT(varchar(5),YEAR(dtDate)) as month,Price FROM tableA ) tb pivot ( sum(Price) for monthin('+@Cols+')) p 'exec(@query)
I have an problem with the order of the results after a join.
My first query works fine and the order of field Name ist correct.
Select * FROM (SELECT * FROM dtree A1 WHERE A1.Subtype=31356 AND A1.DataID IN (select DataID from dtreeancestors where AncestorID=9940974)) t
When I do a join the order of the left table changes
Select * FROM (SELECT * FROM dtree A1 WHERE A1.Subtype=31356 AND A1.DataID IN (select DataID from dtreeancestors where AncestorID=9940974)) t, llattrdata A4 WHERE t.DataID = A4.ID
How can I do a join and keep the order of the left table?
I have a table "Client" that has two columns: "ClientID" and "ProductID". I created on clustered index on ClientID and when I opened the table in the management studio, I saw the table was in the order of ClientID.
Then I added another non-clustered index on ProductID. When I open the table again, it is in the order of ProductID. Shouldn't the table always be in the order of clustered index? Non-clustered index should be a structure outside of the table itself? Did I do anything wrong?
I have to import data into a empty database, that has many tables.some tables have to be inserted first than others due to the foreignkeys.How do I find out the order of the tables that I have to insert datainto?Thanks in advance!Sam
This subject has been posted several times, but I haven't seen a goodanswer.Problem:I want to change the order of the columns in a table using T-SQL only.Explanation:After running your code, I want to see the following table...CREATE TABLE [dbo].[TableName] ([First_Column] [int] NULL ,[Second_Column] [varchar] (20) NULL) ON [PRIMARY]look like this...CREATE TABLE [dbo].[TableName] ([Second_Column] [varchar] (20) NULL ,[First_Column] [int] NULL) ON [PRIMARY]Limitations:Don't post if your post would fall in the following categories:1. If you don't think it can be done2. If you think Enterprise Manager is the only way to do this3. If you think I should just change the order of my Selectstatements4. If you want to state that order column doesn't matter in arelational database5. If you want to ask me why I want to do thisWish:Hopefully the answer WON'T involve creating a brand new table, movingthe data from old to new, dropping the old table, then renaming thenew table to the old name. Yes, I can do that. The table I'm workingwith is extremely huge -- I don't want to do the data juggling.Thanks in advance!
Is it possible to add a column to a table using the "alter table"statement and specify where in the sequence of columns the new columnsits. If not is there any way to alter the order of columns using TSQLrather than Enterprise Manager / Design Table.TIALaurence Breeze
I have two tables, one is called (questions), the second one (answers).
questions columns are (ID,questionTitle)
answers columns are (ID,questionID,answer, answerDate)
I use this query to load data: "SELECT q.questionTitle,COUNT (a.ID),a.answerDate FROM questions q LEFT JOIN answers a ON q.ID=a.questionID" the query is easy, but my problem which I can't solve is how can I fetch the data ordered by the column answerDate, I mean I want the first record to be the one which has the most recent answer and so on.