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

Select statement in form returns related values, not unique values

$
0
0
Can someone take a look at my filter coding. When I give the form a value to search by, the subform returns all related values instead of exactly those that match. For instance, my form has a combo box to search for the appropriate name and populates the box with the name id. If I pick 3 John Smith from the pull down, and hit the search button, I get all matching records for 3 (John Smith), but also any records for name id's that begin with 3, such as 31 Leo Smith, to 39 Zach Smith and 300 (John Doe)! I think the problem is in the Select statement, but I'm not a programmer, so I can't figure out how to fix it. The query2 works perfect by itself, so I know it's not a problem with the query.


Private Sub Show_matching_Click()
' Create a WHERE clause using search criteria entered by user and
' set RecordSource property of Query2 subform.

Dim MySQL As String, MyCriteria As String, MyRecordSource As String
Dim ArgCount As Integer
Dim Tmp As Variant

' Initialize argument count.
ArgCount = 0

' Initialize SELECT statement.
MySQL = "SELECT * FROM query2 WHERE "
MyCriteria = ""

' Use values entered in text boxes in form header to create criteria for WHERE clause.
AddToWhere [Look For 1st Name], "[query cross names1].[name_id]", MyCriteria, ArgCount
AddToWhere [Look For 2nd Name], "[query cross names2].[name_id]", MyCriteria, ArgCount
AddToWhere [Look For 3rd Name], "[query cross names3].[name_id]", MyCriteria, ArgCount

'If no criterion specified, return all records.

If MyCriteria = "" Then
MyCriteria = "True"
End If

'Create SELECT statement

MyRecordSource = MySQL & MyCriteria

'Set RecordSource property of Query2 subform.

Me![Query2 subform].Form.RecordSource = MyRecordSource

'If no records match criteria, then display message.
'Otherwise, move focus to the Clear button.

If Me![Query2 subform].Form.RecordsetClone.RecordCount = 0 Then
MsgBox "No records found to match the criteria you entered.", 48, "No records Found"
Me!Clear.SetFocus

Else

'Enable control in the detail section.

Tmp = EnableControls("Detail", True)
'Move insertion point to Query2 subform.

Me![Query2 subform].SetFocus
End If

End Sub

Thanks

Summarizing All Form Fields Into One

$
0
0
Hello all,

I have created a form that populates a table, but I would like to have a text box that would have a summary of all of the fields on my form at the bottom where the user can easily copy and paste the summarized data into the primary management system as a note.

I am using MS Access 2010.

Example:
Database: Agent_Visit

Table: Agency

Form: Agent_Visit
Form Fields:
Date_Added
Rep
Appointment_Date
Agency_Name

Now at the bottom of the form before the user saves the record I would like to have a text field that would have all of the form field data entered above summarized and separated by commas so the user can copy and paste the data to another location.

In my attempts I have been able to get the first field to populate in the text box at the bottom by using the code below:
Private Sub Note_Click()
Me.Note = Me.Rep
End Sub

But I can seem to figure out how to include other fields in the Me.Note text box.

Any help would be much appreciated

Thank you in advance

MS SQL combining like rows

$
0
0
Hey all I have the following query:
Code:

    SELECT DISTINCT [WL].[Id]
      ,[WL].[UserId]
      ,[WL].[DIF]
      ,[WL].[MW]
      ,[WL].[Notes]
      ,[WL].[WDate]
      ,[WL].[CB]
      ,[WL].[MPH]
      ,[U].[Id]
      ,[U].[UserName]
      ,[U].[We]
      ,[U].[SLength]
      ,[U].[UP]
      ,[U].[PU]
      ,[U].[ANumber]
      ,[U].[G_CK]
              FROM [Wsite].[dbo].[WLog] as WL
        INNER JOIN [Wsite].[dbo].[Users] AS U
                        ON [U].[Id] = [WL].[UserId]
                WHERE [WL].[WDate] >= CONVERT(datetime, '2012-01-01 00:00:00', 120) 
              AND [WL].[WDate] <= CONVERT(datetime, GETDATE(), 120)
          GROUP BY [WL].[UserId]

And the error i get is:
Quote:

> Column 'Wsite.dbo.WLog.Id' is invalid in the select
> list because it is not contained in either an aggregate function or
> the GROUP BY clause.
What I am wanting to do is just conbine the data if there are more than one **UserID** in the list.

As an example:
Code:

    Id  | UserId | .... | Id  | UserName    | SLength | ....
    5843| 99304  | .... | 99304| Bob Barker  | 14      | ....
    5844| 06300  | .... | 06300| Dean Martin | 104    | ....
    5845| 99304  | .... | 99304| Bob Barker  | 8      | ....
    5846| 99304  | .... | 99304| Bob Barker  | 11      | ....
    5847| 7699  | .... | 7699 | John Doe    | 0      | ....

So it should look like this:
Code:

    Id  | UserId | .... | Id  | UserName    | SLength | ....
    5843| 99304  | .... | 99304| Bob Barker  | 33      | ....
    5844| 06300  | .... | 06300| Dean Martin | 104    | ....
    5847| 7699  | .... | 7699 | John Doe    | 0      | ....

Notice that Bob Barker's SLength was combined (14+8+11=33).

Any help would be great! Thanks!

SQL Code - Checking for vacant rooms on hotel database

$
0
0
I am a newbie to both SQL and Access and was wondering if you could help please?

I am in the process of creating a hotel bookings database using Access 2010 but I cannot get my query working where I search for a vacant room.

My database has 5 tables as follows (Field Names in brackets):

BOOKINGS (BookRef, CustAcctNo, BookDate, ArrivDate, DurStay, EmpNo, RoomNo)
CUSTOMERS (CustAcctNo, Title, Forename, Surname, Address1, Address2, Address3)
EMPLOYEES (EmpNo, Title, Forename, Surname)
ROOM TYPES (RoomType, Description, Rate/Price)
ROOMS (RoomNo, RoomType)

These tables all have a 'one-to-many' relationship i.e. one customer can have many bookings.

So, my thinking is that the Fields of interest would be the ArrivDate Field (date of arrival) and DurStay (Duration of Stay) Field. In the Rooms table the Room Number is the Field I am calling out.

So, the closest I have got so far is the following:

PARAMETERS [Start Date] DateTime, [End Date] DateTime;
SELECT R.*, [Start Date] AS Expr1, [End Date] AS Expr2, *
FROM ROOMS AS R
LEFT JOIN (SELECT B.RoomNo
FROM Bookings AS B
WHERE ([Start Date] between B.ArrivDate and (B.ArrivDate + [Please Enter]))
OR ([End Date] between B.ArrivDate and (B.ArrivDate + B.DURSTAY))) AS BKD
ON R.RoomNo = BKD.RoomNo
WHERE (((BKD.RoomNo) Is Null));

This just doesn't seem to be working for me at all. I have tried many times with different versions of the above code but seem to be getting nowhere. My thoughts were that I do a search where the field is null between the dates plus the duration of stay but maybe I am going about it the wrong way I am not sure. However, when I run my query it is returning rooms that are not vacant. An example is as follows:

Room 12 has an arrival date of 10/09/2014 and duration of stay is 3 days. When I run the query Start Date 01/09/2014 and End Date 14/09/2014 it tells me that the room is vacant during these dates.

Hopefully I have provided enough detail here but please let me know if you need to know more. I really appreciate you all having a look at this at least. Maybe a fresh outlook on it might spot where I am going wrong.

Many thanks in advance for any help you can offer.

Interview Questions

$
0
0
Hi guys

I've a MYSQL Database Developer Interview this week. Can you please help me by posting questions an interviewer can ask.
I really appreciate your help.
Thanks in advance :)
:beer:

Hiding ORACLE password from UNIX log

$
0
0
I have a unix script which is hitting the oracle database for a query. The problem is that with the command "sqlplus -S $sqlconn << EOT >> ${parms_file}" , the username and password is visible in the log. Basically the variable "$sqlconn" is declared in a profile file from where the script is calling the value. The profile file has limited access, but the credentials are easily visible in the log. Is there a way to make the password encrypted or suppress this complete line from the log? Also, as an information, the result of the query is written the "parms_file" which is declared in the beginning of the script. A quick help would be very much appreciated . My deadline is monday/ :eek:

Receiving exception when using Sql Server XA datasource

$
0
0
I am trying to use the Sql Server XA datasource, and I am getting the following exception on my db, has anyone seen this error before or can stare me in correct path to address it?

Error:
Code:

javax.transaction.xa.XAException: com.microsoft.sqlserver.jdbc.SQLServerException: Could not find stored procedure 'master..xp_sqljdbc_xa_start'.
                at com.microsoft.sqlserver.jdbc.SQLServerXAResource.DTC_XA_Interface(SQLServerXAResource.java:647)
                at com.microsoft.sqlserver.jdbc.SQLServerXAResource.start(SQLServerXAResource.java:679)
                at com.sun.gjc.spi.XAResourceImpl.start(XAResourceImpl.java:224)
                at com.sun.jts.jta.TransactionState.startAssociation(TransactionState.java:304)
                at com.sun.jts.jta.TransactionImpl.enlistResource(TransactionImpl.java:212)
                at com.sun.enterprise.transaction.JavaEETransactionImpl.enlistResource(JavaEETransactionImpl.java:639)
                at com.sun.enterprise.transaction.JavaEETransactionManagerSimplified.enlistXAResource(JavaEETransactionManagerSimplified.java:1314)

Receiving exception when using Sql Server XA datasource

$
0
0
I am trying to use the Sql Server XA datasource, and I am getting the following exception on my db, has anyone seen this error before or can stare me in correct path to address it?

Error:
Code:

javax.transaction.xa.XAException: com.microsoft.sqlserver.jdbc.SQLServerException: Could not find stored procedure 'master..xp_sqljdbc_xa_start'.
                at com.microsoft.sqlserver.jdbc.SQLServerXAResource.DTC_XA_Interface(SQLServerXAResource.java:647)
                at com.microsoft.sqlserver.jdbc.SQLServerXAResource.start(SQLServerXAResource.java:679)
                at com.sun.gjc.spi.XAResourceImpl.start(XAResourceImpl.java:224)
                at com.sun.jts.jta.TransactionState.startAssociation(TransactionState.java:304)
                at com.sun.jts.jta.TransactionImpl.enlistResource(TransactionImpl.java:212)
                at com.sun.enterprise.transaction.JavaEETransactionImpl.enlistResource(JavaEETransactionImpl.java:639)
                at com.sun.enterprise.transaction.JavaEETransactionManagerSimplified.enlistXAResource(JavaEETransactionManagerSimplified.java:1314)


Compute filed with DLookUp in Query

$
0
0
Hi
I'm designing a query. It's very simple.
I just need to compute something like:

Var: TT[YYZ for this month]-TT[YYZ for last month]

The table is called C1 and has the fields i'm interested
YYZ: Location
TT: number
mxx: date

So, i have for YYZ a list of places and for TT a list of values. MXX has the date of the record on the table. There is one record per date, which it means, there only one record for 1/1/1991 for the YYZ=2.
NF should calculate the difference between the the record on t against t-1.

I've tried with this
Var: YYZ-DLookUp("yyz","[C1]"," "[YYZ]=[YYZ]" AND "[mxx]=DateAdd("m", "-1", "[mxx]"))
But it fails.
Can you guide me?
Thanks a lot for your replys.

PS: i upload a xls sheet with the desired field, Var ,calculated.

Attached Files
File Type: zip Libro1.zip (7.4 KB)

Report group total = 0.00

$
0
0
My report totals monthly costs for a group. As I have it now, that field is blank on the report if total is 0.00. I want it to print 0.00 if no costs in the table for that month.

Greeting and Salutations!

$
0
0
Hi all.
First of all, thank you for this forum. Nice to find a place where people share interest.
I guess this is the place where you introduce yourself to community. Married with children (and a dog), workaholic, pushing 50, like beer :beer: , in serous need to go to gym (at least once a month, let's be real).
English is not my first language so, easy on me, please!
Some 20 years ago I was good at dBase but, careers change, kids need new shoes etc etc. Don't have clue how to even start these days :S.
At my place of work, there is a need for administration software. At a moment is done "manually" and, since i am the one doing it, want to change it. In my head, i think i know what do i want. However, to transfer all those ideas in MS Access database ... it will require time (and beer).
For past month i am playing with all samples and templates available - moving along nicely. However, almost every sample has something that stop me dead! "HtF did they do this???!!!".
So, by finding this forum, i hope for a little help when I got stuck. Willing to share beer :cool:

Change colour

$
0
0
Hi hope someone can help

I have a form that searchers data under a date value.
its a continuous form that depending its results it shows in rows.

The problem I have is that I have set the check box if ticked to change the backcolour of a text box using:

Private Sub Flexi_Urgent__Click()
If Flexi_Urgent_.Value = True Then
Patient_ID.BackColor = 10092543
End If
End Sub

but this changes all text boxes Patient_ID.
I just want the row that contains the tick for the text box "Patient_ID backcolour to change.

Can anyone help?
I hope this make sense
Many thanks

how to select the same record in sqlite?

$
0
0
C:\Documents and Settings\Administrator>d:\sqlite3 d:\test.db
SQLite version 3.8.5 2014-06-04 14:06:34
Enter ".help" for usage hints.
sqlite> create table test(f1 TEXT,f2 TEXT, f3 TEXT);
sqlite> insert into test values("x1","y1","w1");
sqlite> insert into test values("x1","y2","w1");
sqlite> insert into test values("x1","y2","w2");
sqlite> insert into test values("x1","y2","w3");
sqlite> insert into test values("x1","y1","w1");
sqlite> insert into test values("x1","y3","w1");
sqlite> insert into test values("x1","y4","w1");
sqlite> insert into test values("x3","y3","w4");

1)please select the record which contain the same f1 and f2 values, and its rowid.

Here is my method.
sqlite> select rowid,f1,f2,count(f2) from test group by f1,f2;
5|x1|y1|2
4|x1|y2|3
6|x1|y3|1
7|x1|y4|1
8|x3|y3|1

i want the result as
1|x1|y1
2|x1|y2
3|x1|y2
4|x1|y2
5|x1|y1

2)please select the record which contain the same f1 and f2 and f3 values, and its rowid.
Here is my method.
sqlite> select rowid,f1,f2,f3,count(f2),count(f3) from test group by f1,f2,f3;
5|x1|y1|w1|2|2
2|x1|y2|w1|1|1
3|x1|y2|w2|1|1
4|x1|y2|w3|1|1
6|x1|y3|w1|1|1
7|x1|y4|w1|1|1
8|x3|y3|w4|1|1
what i want to get is :

1|x1|y1|w1
5|x1|y1|w1

how can i rewrite my sqlite query command to get the right result?

Change/Delete Rom Permissions and Column Masks

$
0
0
Hi, I trying to figure out a way to change/alter a row permission or a column mask after it has been created in DB2 10.5 ?

Thanks in advance

Display current row permissions and column maks

$
0
0
Is there a ways that I can see all the currently created row permissions and column mask on a table ?

DB2 performance problem

$
0
0
I have low tps in db2 , when i inserted 100000 records in table, it finished after 400 seconds but in informix it finished after 50 second. why?????:(:(:(

Display columns based on MAX() of other column

$
0
0
I am trying to display information based on a MAX(date) function and a GROUP BY function.

However despite being able to display the correct max date the other columns I want to select do not relate the the max date record.

For example (date btw is dd/mm/yyyy)

Table A
name | Date | Notes
----------------------------
John | 10/01/2014 | This is the wrong note
John | 10/02/2014 | Note B
Lisa | 10/01/2014 | This is the wrong note
Lisa | 10/02/2014 | Note B

When I write
Code:

SELECT A.name, MAX(A.Date), A.Notes
FROM A
GROUP BY A.name

My output is
name | Date | Notes
----------------------------
John | 10/02/2014 | This is the wrong note
Lisa | 10/02/2014 | This is the wrong note

Rather than
name | Date | Notes
----------------------------
John | 10/02/2014 | Note B
Lisa | 10/02/2014 | Note B

Can anyone help me on this?

Thanks

Displaying Columns as Rows

$
0
0
I have a query that output students results for an exam. They do around 100 questions, so I was looking for an easy way of displaying the column results into rows, without using UNION as this would take a considerable amount of time.

For example the following table

Name | AA_Answer | BB_Answer | CC_Answer | DD_Answer | EE_Answer |
-----------------------------------------------------------------------
John | 27 | xyz | yellow | rhino | 2.3 |


The query would result the following

Name | Answer Name | Answer Output |
--------------------------------------
John | AA_Answer | 27 |
John | BB_Answer | xyz |
John | CC_Answer | yellow |
John | DD_Answer | rhino |
John | EE_Answer | 2.3 |

Thanks for any help

made by ms access with arabic lang

storing the values of request into a myaql-db

$
0
0
helllo dear database-commmunity

well i am pretty new to Ruby - i need some advices - on the other handside i know MySQL abit better.

i plan to do some requests in osm-files. (openstreetmap)

Question - how can i store the results on a Database -
eg mysql or - (if you prefer postgresql) -

note: my favorite db - at least at the moment is mysql


here the code

Code:


    require 'open-uri'
    require "net/http"
    require 'rexml/document'
   
    def query_overpass(object_type, left,bottom,right,top, key, value)
      base_url = "http://www.overpass-api.de/api/xapi?"
      query_string = "#{object_type}[bbox=#{left},#{bottom},#{right},#{top}][#{key}=#{value}]"
      url = "#{base_url}#{URI.encode(query_string)}"
      resp = Net::HTTP.get_response(URI.parse(url))
      data = resp.body
      return data
    end
   
    overpass_result = REXML::Document.new(query_overpass("node", 7.1,51.2,7.2,51.3,"amenity","restaurant|pub|ice_cream|food_court|fast_food|cafe|biergarten|bar|bakery|steak|pasta|pizza|sushi|asia|nightclub"))
   
    overpass_result.elements.each('osm/node') {|x|
      if !x.elements["tag[@k='name']"].nil?
        print x.elements["tag[@k='name']"].attributes["v"]
      end
      print " | "
   
      if !x.elements["tag[@k='addr:postcode']"].nil?
        print x.elements["tag[@k='addr:postcode']"].attributes["v"]
        print ", "
      end
      if !x.elements["tag[@k='addr:city']"].nil?
        print x.elements["tag[@k='addr:city']"].attributes["v"]
        print ", "
      end
      if !x.elements["tag[@k='addr:street']"].nil?
        print x.elements["tag[@k='addr:street']"].attributes["v"]
        print ", "
      end
      if !x.elements["tag[@k='addr:housenumber']"].nil?
        print x.elements["tag[@k='addr:housenumber']"].attributes["v"]
      end
      print " | "
      print x.attributes["lat"]
      print " | "
      print x.attributes["lon"]
      print " | "
      if !x.elements["tag[@k='website']"].nil?
        print x.elements["tag[@k='website']"].attributes["v"]
      end
      print " | "ll
      if !x.elements["tag[@k='amenity']"].nil?
        print x.elements["tag[@k='amenity']"].attributes["v"]
        print " | "
      end
      puts
    }

look forward to hear from you

again - i would love to store it on a mysql - database - if possible. If you would prefer postgresql - then i would
takte this one.... ;-)

well - i guess that the answer to this will be the same no matter what language we are using.
If the db is a sql database we need to design the database schema and create the tables in the database.

The first step in accessing a db in our code is to get a connection to it.
If ruby is our choice of language, a search for "ruby sql connector" will give us
lots of options to read about.

Well - we also can do it in PHP. What do you think!?

Next, based on the schema we have designed, we need to create queries suitable for storing the data. We will likely need to consider our transactional model.

Again, searching "ruby sql transactional model" will give us plenty of food for thought.
Finally, we may want or need to close the connection to the database.
Viewing all 13329 articles
Browse latest View live