I have a table where each unique entry can have up to 12 'modes', each mode with a start and stop date. A mode is a certain type of characteristic attributed to an entry.
There are 60 different modes and a given mode number can appear in any of the 12 mode fields. I created a very simplistic example table below.
Criteria:
I need to find all entries that have any of the modes = 1
AND for any of the other mode fields = 2 or 3, all modes = 2 or 3 must have a mode_enddate that is NOT NULL.
example:
select * from #temp_work
where (mode1 = 1 or mode2 =1 or mode3 = 1 ...)
And if any of the other mode1-12 fields = 2 or 3 then all mode 2 or 3 mode_enddate must be NOT NULL. I have tried a few different ways to try and get this data, but none of them have been very good.
Create temporary table
create table #temp_work (
id int NULL,
mode1 varchar(20) NULL,
mode_startdate_1 date NULL,
mode_enddate_1 date NULL,
[Code ....
From this limited example, the only valid entry should be ID 1 as the mode = 3 has a NOT NULL mode_enddate.
ID's 2 and 3 both have mode_enddate_X that are NULL, so should not be included.
In the database I am querying, there is a field called "group". I can find out when "group" changes with a time field that was logged whenever group changes. I am trying to find what the value was changed into.
Code: SELECT Assignment_Log.DBID, Assignment_Log.Assigned_Group, Assignment_Log.Submit_Date FROM Assignment_Log
This will tell me:
The unique ID of the database The group it was assigned FROM The time the assignment took place
I need to find the assignment TO
so what I need to do for the last column is something along the lines of...
Find the next record after the current record by looking at the next Submit_Date and view the Assigned_Group.
If no "next record" can be found, leave the cell empty.
Someone ran an update statement multiple times so their are multiple entries in the table. What is the quickest way to track down the multiple entries? I would only want to see where timein and timeoff exist in the table multiple times for the same id. So this would be a duplicate
I am trying to find books which have the same title and publisher name as at least two other books and need to also show the book ref (ISBN number). I have the below script so far:
SELECT isbn, title, publishername FROM book WHERE title in (SELECT title FROM book GROUP BY title HAVING count(title)>2 or count(publishername)>2) order by title;
This is a snap shot of the output:
ISBN Title Publishername 0-1311804-3-6 C Prentice Hall * 0-0788132-1-2 C OSBORNE MCGRAW-HILL * 0-0788153-8-X C OSBORNE MCGRAW-HILL * 0-9435183-3-4 C Database Development MIS * 1-5582806-2-6 C Database Development MIS
[Code] ....
What I should be seeing is only the ones I have put an * next to. What am I missing from the scrip?
If I wanted to search for Jobs as a particular status (e.g. 0130) and wanted to keep the jobs at this status until it has reached 0500, 0125, or 0900 in it's subsequent status log entry, how can I write the SQL for it to achieve it?
I have the following SQL which searches for the Jobs at 0130, but don't know how to develop it further to search on the requirement above.
------ SQL ------- SELECT job.job_number, (SELECT MAX(jsl.job_log_number) FROM job_status_log jsl WHERE job.job_number = jsl.job_number AND jsl.status_code = '0130') as Last_Early_Warning_Status_Entry
[code].....
In the job_status_log table above, there is a job_log_number field which increments by 1 when there is a new status log entry.
Hi , I have two servers, One is with per seat mode another with per license mode. when i am registering one server which is having per seat mode at one of my client machine , it is giving u dont have license permission. Can anyone suggest me regarding license modes if u have two servers.
I have a question, I keep getting the warning where the lookup found duplicate reference key values when caching reference data. It also says to switch over to partial or no cache mode. I switched to partial and and it took way longer to run my package. I have around 200,000 records right now but this table will continue to grow. I guess my question is which mode should I be using? I have another table that will have millions of records in it.
I need to display the recovery mode of ALL databases on a server into a table. (Just like the sp_helpdb prcedure extended with the recoverymodel of each Database). Can anyone give me a hint on this or provide me with a little tsql code snipplet to realize this?
I am having a question on the SSAS2005 OLAP Cubes storage modes. We know SSAS2005 supports 3 different storage modes: ROLAP, MOLAP, HOLAP.
Do all these three storage modes of cubes store data in another physica analysis services databases which are inrelative from their data warehouse (in case they are built on top of the data warehouse)? (so it does not matter at all even we remove the data warehouse?)
Thank you very much in advance for your help and I am looking forward to hearing from you shortly.
I am having a question on ROLAP and MOLAP storage modes. In ROLAP mode, we store all data in source relational databases and though then we can gain near real-time data for the queries. But with MOLAP and Proactive caching, we can solve this problem by setting update notifications to the MOLAP cubes. Also, with HOLAP, we can combine ROLAP and MOLAP (store leaf data in source relational database, while aggregations in MOLAP format), thus we can actually get the near real-time data for the queries as well once there is any changes to the underlying source relational database.
I am just a bit confused about the distinct benefts we can differenciate between these aspects regarding MOLAP with proactive caching and HOLAP. (not convinced about the reason to use ROLAP storage mode).
I hope my question is clear for your help and thanks a lot in advance for your advices and help for that and I am looking forward to hearing from you shortly.
Hi, I am searching for the most easy SQL solution:
Lets say i have 500000 rows of cars in one table with 30000 different car ID's. This table contains no keys, no date values, but I need the last row of these 30000 different cars. How do I get them without adapting table structure and without using cursors ?
I have a table which stores phone numbers of a customer in a table.
Say this table is as below
CustomerName - PhoneNumber Customer 1 - Phone number 1 Customer 2 - Phone number 2 Customer 2 - Phone number 3 Customer 3 - Phone number 4
What would be the best approach to prevent adding another entry against Customer 2. I should be able to add new customers and add multiple phone number against all other Customers. The restriction should be only against Customer 2.
I am trying to pull the last three entries from a table in my database but I am having trouble writing the correct query. The database has multiple entries for each item in my database but I want to pull just the last three for each item. I have tried the TOP function with the items ordered in descending order but that only works when I define each item seperatley. I need to know how to pull the last three entries for every item I have in the table.
Without technical information and DB design, I wish to know the maximum entries in MS SQL in million. I guest for access are a limit of 2 million and a 2GB DB. How much for MS SQL in max. entries and how much in GB?
I'm extracting data from a log (log_history) of patients where nurses perform various actions on a call, such as assessing and reassessing, despatching etc. This is the script:
Select L.URN, LH.THE_TIMESTAMP, LH.ACTION_TYPE, LH.ACTION_BY, LH.ACTION_REQD, LH.NOTE, em.position_type_ref From LOG L Join Log_history LH on (L.URN = LH.LOG_URN) left outer join employee em on (em.code = LH.action_by) Where (L.Taken_at >= :DateFrom and L.Taken_at <= :DateTo) and (LH.ACTION_TYPE = 'D') and (em.position_type_ref ='NU')
Order By L.URN ASC, LH.THE_TIMESTAMP DESC
The result I get shows duplicate 'timestamp' entries and I only want to return unique timestamp entries. Does anyone have any ideas. I'm self taught and have hit a wall
I need help desperately. The following is an example of the data that I have.
I have two tables one name Customers and the other named Orders. The tables have the following attributes
CUSTOMER CustomerNum, CustomerName, OrderNum
ORDER OrderNum, OrderDesc, CustomerNum
Bare in mind that the CustomerNum can have multiple customers attached to it, example a whole family (I know bad database design but it's too late to change) Let's use the following info for the tables respectively
The query i'm using is select Customer.CustomerNum, Customer.CustomerName, Orders.OrderDesc from CUSTOMER, ORDERS where CUSTOMER.CustomerNum = ORDER.CustomerNum
I have an application that allows the user to enter data into a table. There are multiple users so I put in some code that, I thought, would keep 2 users from creating a new record at the same time. The IDs for the records are identical and this is causing a problem.
The IDs are in the format of ####-mmyy. at the start of each month the #### part goes back to 1.
We tried a test today where we had 2 users click on the New button at exactly the same time. The IDs that were created were identical. Is there anyway on the database that I can prevent this from happening?
Here is how I create the new record id:
I get the MAX(ID) from the table I add 1 to the ID and then insert a new record with the new ID into the table.
Hi all can some one there please let me know how to configure error logs. what i observe on some of the servers error log got entries for all conenction, database backup, logbackup etc..... but on some there r entries only about database backup.
Hello,does anyone know what could be wrong? There's a lot of similar entriesin the SQL Server current log:2004-01-21 17:54:00.01 spid57 Starting up database 'DB_NAME'2004-01-21 17:54:06.45 spid57 Starting up database 'DB_NAME'2004-01-21 17:54:59.13 spid56 Starting up database 'DB_NAME'There are hundreds of similar entries that repeat every few seconds. Thedatabase works quite slowly and the users get 'Connection timeout'message very often.Thanks for any advice....:: fabio
Hi All In my application i have to get the data from .csv file. My requirement is that file may consists of duplicate entries I ant to remove the dup entries and i want to place in the table. Waiting for valuable replies Thank u Baba
I have an issue where certain parts of data are repeated several times after i create my query. Without providing my SQL code for now could anyone suggest possibly the main reason(s) for data being duplicated?
Hi,I have a form that should show 2 pictures based on table entries.I want those 2 pictures to be randomly selected based on a database table. So, my table has all the entries, and I want to pull out a random entry that has been approved to display it.Can someone help me with the sql query?I can do SELECT VoteId FROM tblVotes WHERE Approved=True..But how do I make selection a random one that changes every time the user gets another entry?
Hello, I have a reference table. This table has an effective date and end date, and I need to get a single set of values at a point in time. Suppose the following hotel rating values are the values that I want to pull out of the table: 1 Star2 Star 3 Star 4 Star 5 Star This value has other information associated with it (benchmarks and such) and so it's possible that one of the 2 star entries gets end-dated, and then a new 2 Star entry gets created with an effective date and no end date. How can I query so that I only get one 2 Star entry at any point, and get the point in time where the date is between the effective and end date, but only pull back a single set of entries, one distinct rating value. So, suppose the first entry is end-dated 7/1, if I look at old data, I want to see the old benchmarks and so I want the previous entry end-dated 7/1; otherwise, I want to see the new end-date, with the new 2 star entry with no end date. How do I do that? Make sense?
I am a newb at ms sql and was hoping someone could help me eliminate duplicate PRODUCT.PRODUCT from this statement. I have tried using DISTINCT with the same results.The ProductImage table is causing this because the duplicates are from the PRODUCT.PRODUCT that have more than 1 image.
If anyone could rewrite this statement so I can learn from this, it would be most appreciated!
hi, i have a table where i need to update all entries (columns/rows) in 1 queryto make this one clear, if i have table_id firstname lastname1 clayton111 dylan1112 phoebe111 miller111 from the above example, i just want to eliminate all the 111 from the firstname, lastname fields, however, im not sure how to do that in a single query. i asked this because i have like 100 rows and each entries have "111" and i need to remove those. thanks