I am trying to write a stored procedure that updates a value in a table based on the sort order. For example, my table has a field "OfferAmount". When this field is updated, I need to resort the records and update the "CurrRank" field with values 1 through whatever. As per my question marks below, I am not sure how to do this.
Update CurrRank = ??? from tblAppKitOffers where appkitid = 3 AND (OfferStatusCode = 'O' OR OfferStatusCODE = 'D') ORDER BY tblAppKitOffers.OfferAmount Desc
Hi All,I have a table in SQL Server 2000 that contains several million memberids. Some of these member ids are duplicated in the table, and eachrecord is tagged with a 1 or a 2 in [recsrc] to indicate where theycame from.I want to remove all member ids records from the table that have arecsrc of 1 where the same member id also exists in the table with arecsrc of 2.So, if the member id has a recsrc of 1, and no other record exists inthe table with the same member id and a recsrc of 2, I want it leftuntouched.So, in a theortetical dataset of member id and recsrc:0001, 10002, 20001, 20003, 10004, 2I am looking to only delete the first record, because it has a recsrcof 1 and there is another record in the table with the same member idand a recsrc of 2.I'd very much appreciate it if someone could help me achieve this!Much warmth,Murray
I've been looking for examples online to write a SPROC to get some data. Here are the tables.
Album_Category AlbumCategoryID (PK, int, not null) Caption (nvarchar(max), not null) IsPublic (bit, not null)
Albums AlbumID (PK, int, not null) AlbumCategoryID (int, null) Caption (nvarchar(max), not null) IsPublic (bit, not null)
I need to return: -[Album_Category].[AlbumCategoryID] -[Album_Category].[Caption] -[Albums].[Single AlubmID for each AlbumCategoryID] -[Count of Albums in each AlbumCategory]
I hope I was fairly clear in what I'm trying to do. Any tips or help would be appreciated. Thanks.
Hi I have a table with a user column and other columns. User column id the primary key.
I want to create a copy of the record where the user="user1" and insert that copy in the same table in a new created record. But I want the new record to have a value of "user2" in the user column instead of "user1" since it's a primary key
I hope you can help me. I posted this in the microsoft sql server newsgroupa few days ago and got no response so I thought I'd try here. If I canprovide any clarification I'll be glad to do so.I'm trying to calculate a column based on the value of the previous record.I'm not very experienced with SQL-Server.I'm using the following table:CREATE TABLE tblPayment([PaymentID] [int] IDENTITY (1, 1) NOT NULL ,[LoanID] [int] NULL ,[PaymentPeriod] [int] NULL ,[PaymentRecDate] [datetime] NULL ,[PaymentAMT] [money] NULL)I have a view based on this table. That view has the following calculatedcolumnsBeginningBalance: For the first record, this is equal to the loan amountfrom the loan table. For each additional record this is equal to the endingbalance from the previous payment record.Interest: BeginningBalance * the monthly interest rate from the loantablePrincipal: PaymentAMT - InterestEndingBalance: BeginningBalance - PrincipalIt might seem I could use a subquery to calculate the Beginning Balance asin:SELECT LoanID, PaymentPeriod, PaymentAMT,(SELECT SUM(PaymentAMT) FROM tblPayment AS tbl1WHERE tbl1.LoanID = tblPayment.LoanID AND tbl1.PaymentPeriod <tblPayment.PaymentPeriod) AS BeginBalanceFROM tblPaymentWHERE (LoanID = @LoanID)But this will not work, because the interest is calculated on the previousmonth's balance. I need to find a way to loop through the recordset. Isthis possible?Thank you,--Derek CooperDatabase9www.database9.com
Can I dynamically (from a stored procedure) generatea create table script of all tables in a given database (with defaults etc)a create view script of all viewsa create function script of all functionsa create index script of all indexes.(The result will be 4 scripts)Arno de Jong,The Netherlands.
I have a dts package that export data from a database to a text file. I could like to create a validation script to coun the data in the database that should be exported to file and then re-count again after the data is in the text file. Also count the number of columns that is exported.
I would like to count rows by grouping of companys. So for one company when the report display the company employee they are associated a number. Example:
Company: Xrite
User: Tom Smith User # 1
User: Jane Doe User # 2
Company: Xwrong
User: George Green User # 1
User: Mary Jane User #2
I found the function RowNumber(). This function used as follows RowNumber(Nothing) Returns a row number for each record of the table instead of by company name (which is the group by).
Is there a way to use this function RowNumber() or any way in SRS to get the results I'm looking for?
In the database, there is Date, Store#, Item#, and %Total Sales. In some cases, the same item# for the same date may be given more than one value for '% of Total Sales'. (For some reason this is a valid business scenario that happens rarely, but it happens.)
In that situation only, the requirement is to sum the two values together into one line. So if Item# 123 has a line with a value of .05%, and another line with a value of .08%, I need to sum those two values into one line for Item #123 that has a %Total of .13%. ONLY when an item has more than one percentage assigned, those percentages should be summed. Otherwise, if an item# has only one percentage value assigned, we just want to see that value.
Basically, I would like to implement logic that would work like this:
SELECT Date, Store#, Item#, CASE WHEN Count(%Total Sales) >1 THEN Sum(%Total Sales) ELSE %Total Sales END
FROM (some tables and joins) GROUP BY Date, Store#, Item#
However, I'm not sure how to craft it so that I don't get a syntax error (this query produces errors).
Hi~, I have 3 questions about memory based bulk copy.
1. What is the limitation count of IRowsetFastLoad::InsertRow() method before IRowsetFastLoad::Commit(true)? For example, how much insert row at below sample?(the max value of nCount) for(i=0 ; i<nCount ; i++) { pIFastLoad->InsertRow(hAccessor, (void*)(&BulkData)); }
2. In above code sample, isn't there method of inserting prepared array at once directly(BulkData array, not for loop)
3. In OLE DB memory based bulk copy, what is the equivalent of below's T-SQL bulk copy option ? BULK INSERT database_name.schema_name.table_name FROM 'data_file' WITH (ROWS_PER_BATCH = rows_per_batch, TABLOCK);
------------------------------------------------------- My solution is like this. Is it correct?
// CoCreateInstance(...); // Data source // Create session
How do I write a query to give me the total records in databaseA.tableA divided by the total records in databaseB.tableA This is what I have so far:DECLARE @today as datetime DECLARE @past as datetime
/* set the dates */ set @today = getdate() set @past = getdate() - 3 /* Go back 3 days */
/* create temp table for holding total cases*/ CREATE TABLE #CaseTotalCount ( TotalCount int )
/**/ CREATE TABLE #FlashCycleCount ( FlashCount int )
/**/
INSERT INTO #CaseTotalCount (TotalCount) SELECT COUNT (DataBaseA.dbo.tblProcedureData.CaseID) as TotalCount FROM DataBaseA.dbo.tblProcedureData WHERE DataBaseA.dbo.tblProcedureData.Date < @today AND DataBaseA.dbo.tblProcedureData.Date > @past
/**/ INSERT INTO #FlashCycleCount (FlashCount) SELECT COUNT (DataBaseB.dbo.tblFlashLog.FlashLogID) AS FlashCount FROM DataBaseB.dbo.tblFlashLog WHERE DataBaseB.dbo.tblFlashLog.LoadDate < @today AND DataBaseB.dbo.tblFlashLog.LoadDate > @past
/*function call*/ SELECT dbo.percentage(#FlashCycleCount.FlashCount, #PeriOpTotalCount.TotalCount) FROM #FlashCycleCount JOIN #PeriopTotalCount ON #PeriOpTotalCount.TotalCount != 0 This works but when I try to bind this to a formview a get nothing. any ides?
I I have a GridView with paging enabled which is bound to a SqlDataSource. I'd like to be able to tell the user how many records were returned in total by the SqlDataSource. Is there any way to do this without re-running the query?
hello friends i have table1 in aspnetdb.mdf. my cloumname usernumber and my datatype is int. how may can be usernumber ? what is the max usernamber ? or there is bigint as datatype.. what is the max usernumber for bigint ? if you tell me about int32 and int 64, i couldnt find int32 and int64 as datatype in table1 in aspnetdb.mdf cheers
I am trying to limit the number of records to start in a position and show me "n" records. Here is an example query:
SELECT TOP 60 * FROM Entries WHERE Id NOT IN ( SELECT TOP 45 Id FROM Entries ORDER BY Id DESC ) AND Static = False AND Authorized = False ORDER BY Id DESC
I have been assigned to fix a script which i did not write and that is not in SQL, but calls to SQL to get it's results.
It reads from a payroll table in SQL with 943 total records (of which about 280 are active employees).
When i run the script, i receive a series of errors listing the field that the error is in (ie: Badge or PayRule) and the record # causing the error.
My problem is that the 1st record # that returns an error is #946. I get a total of 45 records that generate errors of this sort. (ie: #946-957 Badge, 1154-1159 Badge, 1482-1497 PayRule, 1562-1568 Badge, 2083-2086 PayRule).
IF i can figure out which employee those records belong to I will have a much better chance of finding the cause of the errors and correcting them.
When it gives a record #, i always thought it was the row in the table that was referred to, but since the record #'s i am receiving are larger than the number of rows in the table, i am utterly confused!
So...i guess my question is, how do I count the records if not by row?
There a stored procedure or query that will count all the recordsin all my tables in a database.One of these two -exec sp_MSforeachtable N'SELECT "table" = ''?'', cnt = COUNT(*) FROM ?'select object_name(id), rows from sysindexes where indid in (1, 0)Is there a way to add columns to the second query? I would like to seehow many columns and their names as well.Thanks.
I have x amount of tests for a person on a particular day. There are criteria to invalidate a test. I can filter all the bad tests away, but now I need to only accept 2 valid tests per day, even if there are more tests. The tests are filtered according to person ID and then put in order by date. I need to accept the first 2 valid test based on the criteria and reject the others. Any suggestions
I am trying to create an asp page that will update an Access 2000 database. I need to update records if the user exists and create a new record if the user does not exist. Most of the variables are pulled from a separate "post" form.
I am using 2 pieces of info to find duplicates, as employee numbers can be assigned to multiple employees. Right now I have the page check for a duplicate employee id number then check for a duplicate last name. Unfortunately it is running each check separately, so if the last name is duplicated anywhere, it is sending a duplicated value.
here is the chunk of code in question... all RF_variables are request.form variables
cnt="SELECT COUNT(emp_id) AS Xnum FROM " & RF_course cnt=cnt & " WHERE emp_id='" & RF_emp_id & "'" set again=conn.Execute(cnt) dup=again("Xnum")
if dup>=1 then cnt="SELECT COUNT(lname) AS Xnum FROM " & RF_course cnt=cnt & " WHERE lname='" & RF_lname & "'" set again=conn.Execute(cnt) dupl=again("Xnum")
if dupl=1 then upd="UPDATE " & RF_course & " SET " upd=upd & "section" & RF_section & "='" & RF_score & "'" upd=upd & " WHERE emp_id='" & RF_emp_id & "'" upd=upd & " AND lname='" & RF_lname & "'" on error resume next conn.Execute upd else ins="INSERT INTO " & RF_course ins=ins & " (lname,fname,emp_id,cname," ins=ins & "section" & RF_section & ")" ins=ins & " VALUES " ins=ins & "('" & RF_lname & "'," ins=ins & "'" & RF_fname & "'," ins=ins & "'" & RF_emp_id & "'," ins=ins & "'" & RF_cname & "'," ins=ins & "'" & RF_score & "')" on error resume next conn.Execute ins end if else ins="INSERT INTO " & RF_course ins=ins & " (lname,fname,emp_id,cname," ins=ins & "section" & RF_section & ")" ins=ins & " VALUES " ins=ins & "('" & RF_lname & "'," ins=ins & "'" & RF_fname & "'," ins=ins & "'" & RF_emp_id & "'," ins=ins & "'" & RF_cname & "'," ins=ins & "'" & RF_score & "')" on error resume next conn.Execute ins end if
Hopefully this is understandable. If anyone can offer any help I would greatly appreciate it.
I have a fact table with a create time dimension and an expiration time dimension. I'd like to have a calculated member that would compare the (count for create time) / (count with that expiration time). I already have these counts as measures.
I would be able to put the create time dimension in the "row fields" area, and see the ratio (calculated above) over the different create time periods.
Can someone point me in the right direction on how I would create that kind of calculated member? What would the MDX look like?
We are developing a database in SQL and we are trialing some of our typical analysis undertaken on out dataset.
I have a problem with a update function. ID direction Holiday Lat Long Speed obstime - Datestamp LicenseID - varchar(7) status - int (0 or 1) O-Unoccipied, 1-occupied Pickup - Boolean Dropoff - Boolean
I am trying to update the 'Pickup' or 'Dropoff' when the status changes from 0 to 1 or from 1 to 0 if the difference in the datestamp is less than 2 minutes. Pickup is when the status goes from 0 to 1 Drop off is when the status goes from 1 to 0
We are currently developing a crm that has the following main tables: client, sales, actions, contacts and employees with up to 4 million records. The db contains several other tables with extra information but these aren't relevant for this problem. Clients have sales, contacts and actions. sales and actions can have seperate contacts as well, and contacts can be related to employees in a way.
Offcourse a security model was implemented but this only provides the option to hide or show all the records of these main tables. Now people noticed that it is a must to let people see for example only companies they created or do sales with. In other words access must be given at a record level.
The first thing that pops in my head is to create a client_security, sales_security, ... table that contains the employee_id and client_id or sales_id, or ... And add a join with one of these security tables for each select that is executed.
I wonder (because of the huge amount of data) if there isn't a better way to get this done?
Another possible issue that came to mind was, that when some data doesn't need protection or some people have the rigth to see everything, we would have to create the records in the security table anyways, resulting in probably hundreds of thousands of records.
Feedback on our solution (if we can call it that allready), or even keywords to find more about this issue via google (record based security really isn't the best description I guess) are most appreciated.
My boss would like a list of all the tables in a specific database and their record counts. There are over 80 tables in this database, so doing one by one is not something I have time for. Does anyone know of a system table that stores this information or an easy way of doing this?