Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 SQL Server 2008 Forums
 Transact-SQL (2008)
 duplicate data in a view

Author  Topic 

ElianeAsmar
Starting Member

2 Posts

Posted - 2014-02-23 : 07:37:08
Hello. I have 3 tables:
members(serial, name,address,phone)
membercars(memberid,color,make,model,)
memberpayments(memberid,from date,expirydate,amout,tax)
the memberid in membercars and memberpayments, is the serial in members.
i created a view: membersvw that contains the fields of all these three tables.
But there is a problem. If one member has more than one payment, i will find the member more several times in the view.

How can i solve this problem?

ElianeAsmar
Starting Member

2 Posts

Posted - 2014-02-24 : 05:32:29
Solved :).
I just added an order by and group by to the queries.


Private Sub btnFilter_Click(sender As System.Object, e As System.EventArgs) Handles btnFilter.Click

Dim strsql As String = ""
If mcon.State = ConnectionState.Closed Then mcon.Open()
If cmbFilter.Text = "Name" Then
strsql = "select serial,name, familyname from membersvw where name like '%" & txtFilter.Text & "%' group by serial,name,familyName order by name "
ElseIf cmbFilter.Text = "Family Name" Then
strsql = "select serial,name, familyname from membersvw where familyname like '%" & txtFilter.Text & "%' group by serial,name,familyName order by name "
ElseIf cmbFilter.Text = "Tag" Then
strsql = "select serial,name, familyname,Tag from membersvw where tag like '%" & txtFilter.Text & "%' group by serial,name,familyName,tag,memberCar order by tag "
ElseIf cmbFilter.Text = "Make" Then
strsql = "select serial,name, familyname,Make from membersvw where make like '%" & txtFilter.Text & "%' group by serial,name,familyName,make,memberCar order by make "
ElseIf cmbFilter.Text = "Model" Then
strsql = "select serial,name, familyname,Model from membersvw where model like '%" & txtFilter.Text & "%' group by serial,name,familyName,model,memberCar order by model "
ElseIf cmbFilter.Text = "Color" Then
strsql = "select serial,name, familyname,Color from membersvw where color like '%" & txtFilter.Text & "%' group by serial,name,familyName,color,memberCar order by color "
ElseIf cmbFilter.Text = "Plate" Then
strsql = "select serial,name, familyname,Plate from membersvw where plate like '%" & txtFilter.Text & "%' group by serial,name,familyName,plate,memberCar order by plate "
Else
btnNoFilter.PerformClick()
Exit Sub
End If
Go to Top of Page
   

- Advertisement -