Quantcast
Channel: dBforums – Everything on Databases, Design, Developers and Administrators
Viewing all 13329 articles
Browse latest View live

Query that creates a row for each day of the month

$
0
0
we collect data on a monthly basis but now a query is needed to break down the monthly amount into a daily figure. I have everything working except the ability to take the user's input from a date field and have the query create a row for each day of the month from the date entered. i.e.
01-01-13
01-02-13
01-03-13...
up to
01-31-13

can anyone provide a solution to this problem? it would be greatly appreciated!

Adding a Variance row to a pivot table?

$
0
0
Having trouble figuring this out. It may not even be possible. I am trying to add a variance row to a pivot table. The table shows revenue for 2012 and 2013 by month. I want to add a column under 2013 that shows the difference (2013-2012).

I know you can add custom calcs between different columns but not sure if you can for values within a column. The attached images show what i am trying to do. Is this possible? :eek:

Attached Images
File Type: png excel1.PNG (6.9 KB)
File Type: png excel2.PNG (7.1 KB)

Need QUERY for DELETE

$
0
0
I have a query to select list of patients based on some condition. But I need to delete those instead of selecting. Here is the query:

SELECT
[p].[Patient_ID],
[p].[Last_Name],
[p].[First_Name],
[p].[MI]
FROM [Coupon].[dbo].[Patient] AS [p]
JOIN [Coupon].[dbo].[Patient_PLPPrescriberSite_Xref] AS [ppsx] ON ([ppsx].[PatientID]=[p].[Patient_ID])
JOIN [TCPLP].[dbo].[PrescriberSiteXref] AS [psx] ON ([psx].[PrescriberSiteXrefID]=[ppsx].[HCP_PLP_EnrollmentPrescriberSiteXrefID])
JOIN [TCPLP].[dbo].[PrescriberSite] AS [ps] ON ([ps].[PrescriberSiteID]=[psx].[PrescriberPersonID])
JOIN [TCPLP].[dbo].[Person] AS [ph] ON [PersonID]=[psx].[PrescriberPersonID]

WHERE
([ps].[Description] IN ('n/a', 'N/A', ' ')) OR ([ps].[Description] LIKE '0%')
OR ([ph].[LastName] IN ('n/a', 'N/A', ' ')) OR ([ph].[LastName] LIKE '0%')

SELECT
[p].[PersonID],
[p].[LastName],
[p].[FirstName],
[p].[MiddleName]

FROM
[R2].[dbo].[Person] AS [p]
JOIN [R2].[dbo].[R2EnrollmentSiteDetails] AS [esd] ON ([esd].[PatientID]=[p].[PersonID])
JOIN [TCPLP].[dbo].[PrescriberSiteXref] AS [psx] ON ([psx].[PrescriberSiteXrefID]=[esd].[TP_PLPPrescriberSiteXrefID])
JOIN [TCPLP].[dbo].[PrescriberSite] AS [ps] ON ([ps].[PrescriberSiteID]=[psx].[PrescriberSiteID])
JOIN [TCPLP].[dbo].[Person] AS [ph] ON ([ph].[PersonID]=[psx].[PrescriberPersonID])

WHERE
([ps].[Description] IN ('n/a', 'N/A', ' ')) OR ([ps].[Description] LIKE '0%')
OR ([ph].[LastName] IN ('n/a', 'N/A', ' ')) OR ([ph].[LastName] LIKE '0%')




Can anyone tell me the query plzzz

Thanks

Cant uninstall and reinstall postgresql 8.4.

$
0
0
Cant uninstall and reinstall postgresql 8.4.

I have tried for about 6 hours now to get it working again.

There was a problem with the database and I decided it best to reinstall the program.

Im on W7 64, I used revo uninstaller.

I also manually deleted the user files 'postgres' and postgres files in the program files folder.

i used command promt with 'net user postgres /delete'

when i try to re-install 8.4 i get an error message saying it was unsuccessful.

I then have to uninstall what was installed that time and i tried different versions.

postgres 9.0/9.1/8.39 all had errors installing.

Also i can see after each failed install I get 'postgres.exe' files in process explorer and one of them is using 50% CPU.

there has to be something im missing. If i uninstalled the program surely when its installed again it would not be using 50% CPU, before it was barely using 3%.

XMLQUERY case-sensitive

$
0
0
Hi experts!

Sorry to trouble you but I've got an issue while using XQMLQUERY, i'm getting some info from an XML's document but sometimes the tag use a capital lettr and sometimes in lower case only, example:

-- Capital
PHP Code:

<Cabecera>
    <
ID_TRANSACCION>GC201211050023</ID_TRANSACCION>
    <
CVE_TRANSACCION>1       </CVE_TRANSACCION>
    <
ID_ACTOR/>
    <
ID_ROL>1  </ID_ROL>
</
Cabecera

-- lower case
PHP Code:

<cabecera>
    <
ID_TRANSACCION>GC201211050023</ID_TRANSACCION>
    <
CVE_TRANSACCION>1       </CVE_TRANSACCION>
    <
ID_ACTOR/>
    <
ID_ROL>1  </ID_ROL>
</
cabecera

So, whene y use the XQMLQUERY i've got to change the query.

Thank for your help.

Best regards.

How to create an employee database

$
0
0
I am new to creating databases, but I am trying to create an employee database to hold all of an employees information.

Employee Information Includes:

Name
Social Security #
Date of Birth
Address, City, State, Zip
Drivers License #
Drivers license state
Drivers License Exp. Date
Medical Card Exp. Date
CDL Classification
Union Home Local
Union Ticket #
Union Classification
Emergency Contact Name
Emergency Contact Relationship
Emergency Contact Phone Number


I also want the database to be "searchable" so that I can search for a certain employee.

We are in the construction industry so we do not have steady work. We hire people and lay them off when we run out of work. I would like to incorporate working dates for each employees as well as short notes on how the employee worked during those date (ex. safe and productive or caused trouble).

For Example: Employee John Doe worked for us from 11/27/2012 - 12/23/2012. Employee worked safe and productive, layed off due to a lack of work.

But I would like to be able to add working dates everytime this employee works for us. That maybe 10 times within the coarse of a year or it maybe twice and he was fired for some reason.

I would also like to be able to keep a record of any driving tickets or any safety violations they receive.

Not sure which program to use or how to create this type of database. I have a mac computer so, I know there are less programs for mac than there are PC.

All Help is greatly appreciated.

Thanks,

Search inside search results

$
0
0
Hi
Does anyone have a script to search inside search results.
Normally records are stored in folders and furthers easy to search with user input.
I have brought the search results to the centre or left query windows. From there I would like to search further and bring the results to the centre or left query window again.
To some extent I tried to use filter record set through recordset script but still the flexibility like searching in folder is missing. It will be good if we are able to store the records temporarily on air.

Search for missing values in SQL. Advanced Query

$
0
0
KEY ID GROUP
1 1 a
2 1 b
3 2 a
4 2 b
5 3 a
6 3 b
7 4 a
8 5 a

This is my simple table I need a query that will identity the ID's that are missing the group "b" but I don't want ID 1,2,3 to come up because they are part of a and b. I just need to see anything missing only "b" but not if it's part of a and b.

query should reveal answer should be missing the group b
KEY ID
7 4
8 5

I tried the NULL search but since the records dont exist it cant find a null. Any help on writing a query to identify the missing ID without B but exclude ID that are part of A and B

Hope this makes sense, Please help.

Company Person Realationship

$
0
0
I have a schema question about a database I am putting together. The database will be used to track the contact information and dialogs we have with people at the various companies we work with. These people may leave a company to work somewhere else but I want the relationships that the letter creates, both to the company and person to be preserved in the DB. In the future I can call a company, and in the past I spoke with so and so, or call the person and see that while there were at the previous company we discusses this and that. What is the best way to set this up in the DB?

1. have a table that has a primary key of say "PersonCompany" and then foreign key of "Company" and foreign key of "Person". So if I want to log a letter to a person at a company I would just use the PersonCompany PK and the letter would always have association with both entities (person and company)

2. Instead of a single value (PK) to capture the relationship between a person and company. Should I use two foreign keys, one for the person and one for the company, to indicate the letter has a relationship to both entities.

Both methods seem to work, but I'm wondering what is the most appropriate way to set up this relationship.

Thanks,
Dave

Selling large email databases

$
0
0
Hello,

I would like to know, where is the best place i can sale my Data Bases,
I have more than 500K emails in the industries of Forex, Casino, Affiliates, Option Binary and etc..

Please contact me back to my email bancdedata@gmail.com for more information, thank you!

SQL Server data read using vbs

$
0
0
Hello all. I'm quite inexperienced with vbs and I'm trying to write a VBScript function that will take the following arguments and return success if all returned fields from the query are less than 'Max Age' hours old.

Accept arguments:
SQL Server or Server\Instance
SQL Account Username
SQL Account Password
SQL Query
Max age (in minutes)

Return 0 for failed
Return 1 for succeeded

Example Query:
SELECT [last_execution_date]
FROM [DB].[dbo].[task_tbl]

examples of existing data (SQL data type is datetime):
2013-01-13 22:00:11.323
2013-01-13 23:00:11.933

so basically a compare between the provided Max Age and the dates retrieved by the select. In other words: Tell me everything is fine if last date in DB is 10 mins ago...if the last date is older than that, I want to be alerted. Could anyone give me a hint on how I go about achieving this?

Thank you

SQL Query - So close yet so far

$
0
0
I have a complicated problem which I shall describe with some simple sample tables and my query

Tables:
Notes
NoteID Heading CreationDate UserID CustomerID2
{6 notes made by users for customers)

Customer (I am working with a database that combined two different customer tables together.)
CustomerID CustomerID2 Name CreationDate
{5 distinct customers}

User
UserID Name CreationDate
{5 distinct users}

Appt
ApptID Event EventDate CreationDate UserID CustomerID
{10 Events created by users for customers}


Query:
SELECT
(SELECT TOP 1(Note.UserID) FROM Note
WHERE
(Customer.CustomerID2 = Note.CustomerID2)
AND (Note.CreationDate <= Appt.CreationDate)
ORDER BY Note.CreationDate DESC) AS NoteUserID
FROM Appt
JOIN Customer ON Appt.CustomerID = Customer.CustomerID
WHERE
Appt.EventDate = '2013-01-14'



This would result with:
User1
User1
User2
User3
User1
NULL

I want instead:
User1 3
User2 1
User3 1
NULL 1


How might I do this without creating an additional table and querying the created table?

I would be grateful for any help provided.

how to Script Out Linked server with passoword

$
0
0
I have couple of linked servers on SQL server 2005 need to migrate to another SQL server 2005.I have to script out remote login password as well. when i script out Linked server,it won't bring password. it come up with hashed '#####'. There is no way to find out password from my team or application users. Is it possible to script out linked server with remote login credential ?

Can someone guild me how to resolve this issue ?


Thanks
SQLDBA346

New to DB2

$
0
0
Hello Everyone.

I'm (somewhat) new to DB2. Essentially, I work as a data analyst for a consulting group. Most of the time, I get to work with Microsoft's SQL Sever, however a particular client has a particular need that we do the programming on their system which happens to be DB2. In addition, these people have a large customer base.

I've got a few different questions, and so I'll break them down into different posts as I come across the challenge.

First question:

I have 4 massive tables that I need to join together.
Each table has about 7 million rows.
* One table has transaction date information.
* One table has customer information.
* One table has account information (a customer can have multiple accounts)
* And one table has summary information (that I have created)

I want to join all this together into one table. This one table is fed into a proprietary data analysis tool and for speed reasons, its best to have all the data in one massive table fed into the tool. (The tool can handle it... its not he bottleneck.)

When building the query to do this, we've run into a lot of speed issues.

So, what is the best game plan for doing this efficiently?

I've tried putting clustered indices on the tables' keys and doing the joins one at a time.

So to walk you through it...

The transaction table table has the transaction start and stop dates, along with the customer ID number. I have set a clustered index on those 2 fields and then join the customer information onto the table using the transaction dates and the customer name. On this table, I add an index for the transaction dates, customer number, and account number. Then I join on the account data using those 3 fields as the key.

We end up with a pretty massive table with about 70 columns and 8 million rows. (Entirely because some customers have multiple accounts).

However, this whole join process takes a good 20 hours or so to do. I'd like to see if that sounds reasonable or if anyone has advice on creating mega-tables like this one.

Does this seem slow to you people? When we've built data like this before, we've typically had *much* smaller tables and better hardware. I'm wondering if I'm going about writing this query all wrong.

Would writing one massive join perform better? I made an initial stab at that, but it seemed to be even slower than this process.

Thanks in advance.

how to delete subscription in rep server

$
0
0
I am trying to drop connection
1> drop connection to ec_dco.ec_dco
2> .
Msg 15039, Level 12, State 0:
Server 'pr_repsrvhq01':
Database 'ec_dco.ec_dco' has subscriptions in it. Cannot drop connection to it.
1>

rs_getsub does not show any subscriptions, however, rs_subscriptions table has two entries for that dbid, but for some reason, pdbid is 0 for these two records. And rs_databases does not show any databases with id 0. I am hesitating to manually remove these two records from rs_subscriptions, is there any other way for me to do it properly and remove any dependant subscriptions? Thank you

what is the maximum length

$
0
0
what is the maximum length of "in (1,2,3)" in mysql

RAC One Node failover doesn't work?

$
0
0
Hello, good people :)

This is my problem:
Recently our company bought two Exadata racks Eight Rack (every one in RAC One Node configuration). Linux x86_64, Oracle 11.2.0.3 Enterprise Edition.

I rebooted one node (Node1) managing live instance, and i thought that other, "surviving" node (Node2) will automatically mount and open an instance. But, nothing was happened during reboot of Node1. After the Node1 was up, instance was automatically started, mounted and opened on Node1.During the reboot, database was down

What I am doing wrong? Just to say, I didn't find very useful documentation about RAC One Node.

Thanks a lot!

How to run select statement on column with type timestamp

$
0
0
Hi all one of my columns type is

"DATEON" TIMESTAMP NOT NULL WITH DEFAULT CURRENT TIMESTAMP ,


column content is 10/4/2006 2:34:43 PM


how to run select statement on this particular column

and i want to select particular period of time aswell.

Easy Online Jobs Offer Affiliate Program - Jan-1301(M000398)

$
0
0
Affiliate programs are often called home business opportunities or ways to work from home online, but essentially they are all pretty much the same thing with minor differences other than the niches they are targeting. They can become very profitable and make you a substantial amount of money every month if you are willing to put in the necessary time and effort. Continue reading to find our highly recommended online business programs, opportunities, and resources for making money on the internet. Now you can earn hundreds and thousands of dollars by referring!

Attendance Entry

$
0
0
I am trying to create attendance entry system, where the system will perform the following tasks:
1. Individual or whole class %age attendance for all subjects of a particular semesters, particular departments some specified class section or individual subjects of a particular semesters, particular departments some specified class section.
2. %age analysis of whole class or particular student for all subjects of a particular semesters, particular departments some specified class section or individual subjects of a particular semesters, particular departments some specified class section for a supplied range of attendance %age. For Example: I want to know a what is %age of class attended by a student A of Computer Science department, 3rd Semester, Sections A who are falling in the range of 70-80%
3. I also want to perform the above two analysis against a particular faculty or all the faculties who are taking class to which student A belong to.
4. Number of classes taken by individual faculty of each departments particular semesters some section.

Now I am listing all tables with attribute names.
a. Departments(Department_ID, Department_Name) sample values are 1, 'CSE'; 2, 'ECE' etc...
b. Subjects(Subject_ID, Subject_Title, Subject_Code, Subject_Credit) sample values are 1, 'Java Programming', 'CS 506', 4; 2,'Database Management System', 'CS 503', 4
c. Periods(Period_ID, Period_Name), sample values are 1, 'First Period'; 2, 'Second Period'..... till 'Tenth Period'
d. Sections(Section_ID, Section_Name), sample values are 1, 'Section A'; 2. 'Section B'; 3. 'Section C'
e. Semesters(Semester_ID, Semester_Name, Semester_Type), sample values are 1, 8, 'even'; 2,7,'odd', 3, 6, 'even'.....so on till 8,1,'odd'
f. Students(Student_ID, Student_Name, Semester_ID, Department_ID, Class_Roll, Section_ID, Group_ID)
g. Lab_Group(Group_ID, Group_Name), sample values are 1,'Group A'; 2, 'Group B'
h. Attendance(Attendance_ID, Attendance_Status), sample values are 1, 'Present'; 2,'Absent'; 3,'Leave'
Now the problem I am facing is what will be table structure and how to store the attendance of several students in a separate table to perform the above mentioned tasks.
Please Advice this as soon as possible.
Viewing all 13329 articles
Browse latest View live