|
With (1) you would have to hardcode any combobox (for example) containing the different possible entries.
With (2) you wouldn't know which one is each..
Diff between 2 and 3 would be that in the program itself you would have to use:
someMatch.Status.Finished == true
vs
someMatch.Status.Description == 'finished'
But im not convinced, though, of solution (3)
|
|
|
|
|
Alivemau5 wrote: With (2) you wouldn't know which one is each..
public enum MatchStatus
{
NotStarted = 1,
FirstHalf = 2,
HalfTimeBreak = 3
}
If you have code relying on this, the enumerate it in code.
|
|
|
|
|
You have convinced me.
And for users privileges do you think its a good idea to have the following?:
Users (UserId, UserTypeId, ..)
UserTypes (UserTypeId, Name, MayAddMatch, MayDelMatch, May..., May.., May... )
with registries like (1, "Admin", true, true, true...)
(i'm not doing an offtopic.. its a similar question)
|
|
|
|
|
Alivemau5 wrote: With (2) you wouldn't know which one is each..
You could know which one is which this is how we do it.
This may not be the cleanest way but it is very easy to maintain.
We create an integer array such as Dim blah() as Integer and set a default size for it close to what we think the number of records will be to minimize the use of redim.
Then do something like this with the record set you retrieve.
While myReader.Read
cmbControl.Items.Add(myReader.GetString(1))
lKeyIndex(lIndex) = myReader.GetValue(0)
'
lIndex += 1
' see if we need to redimension the array...
If lIndex Mod iCurrentDim = 0 Then
iCurrentDim = iCurrentDim + iDefaultDim
ReDim Preserve lKeyIndex(iCurrentDim)
End If
End While
Here is a example query.
SELECT `UniqueNumber`, `Description` FROM `ct_contsources_master` WHERE `Inactive` = 0 ORDER BY `Description`
Notice the Inactive flag...
If you use this than if a row is no longer valid you can set it to 1...therefore not populate the combo.
EDIT..
Oh yeah this will help..
Public Function fiSetComboIndex(ByVal lKey As Long, ByRef cboControl As ComboBox, ByRef lKeyIndex() As Long) As Integer
' this routine sets the current "SelectedIndex" to the lKey passed in...
Dim iII As Integer
Dim iKeyIndexLength As Integer = lKeyIndex.Length - 1
'
fiSetComboIndex = 0
For iII = 0 To iKeyIndexLength
If lKeyIndex(iII) = 0 And iII > 0 Then
Exit For
End If
If lKeyIndex(iII) = lKey Then
fiSetComboIndex = iII
Exit For
End If
Next
End Function
Use this to get the value that is selected.
blah(comboBoxName.SelectedIndex)
Store the result of that in the main table.
Humble Programmer
|
|
|
|
|
Depends on what questions you want to answer.
If the only question you want to answer is 'What is the status of a match?' then first suggestion is good enough. This effectively means you have a one-one relation between matches and statuses.
If you want to answer questions like 'What were half-time and full-time scores of a match?' then you have a one-many relation between matches and statuses so you need to use your second suggestion.
Your third suggestion seems to offend first order normalization.
I'd go for the second approach because it's more flexible. This may also mean moving some columns from Matches into the statuses table (e.g. the score since you have both half and full time scores).
Regards
David R
---------------------------------------------------------------
"Every program eventually becomes rococo, and then rubble." - Alan Perlis
|
|
|
|
|
Well my second suggestion was more like a table with 5 registries than a table with n registries, that is:
(1, Not started)
(2, First Half)
(3, Break)
(4, Second half)
(5, Ended)
And no more columns.. not this:
(1, Not started)
...
(23, Not started)
I think you understood that
This second suggestion was thinking on that I could fill any later combo (for example) without hardcoding it.. but the enum solution works and I wouldnt need to hardcode.
|
|
|
|
|
Alivemau5 wrote: My question is, what is the correct way of modeling this?
Normalization[^] would be the way to go, with most tables ending up in the third normal form.
A joking reference during design would be "The Key, the whole Key, and nothing but the Key, so help me Codd[^]"
I are Troll
|
|
|
|
|
I say 2 because that would be normalized. The enum would prevent hard coding but you really don't want to have to refer to app anytime you want to know what the value is...
For instance if you are just looking at the data in the table not in the app.
Also if you do it the second way rather then the enum you don't have to modify the enum every time you add a row.
Humble Programmer
|
|
|
|
|
The second way, definitely -- plus an enumeration in your code.
P.S. See my GenOmatic[^].
|
|
|
|
|
Isn't bad that the table with states would be finite (5 registries) and readonly?
|
|
|
|
|
No, and it would leave room for more in the future. And maybe you would use it as the base for other sports, like American football or baseball or who knows what.
It's a proper pattern to use anyway, even if there are only two entries.
|
|
|
|
|
hi, iam using asp.net with c# with sql server databae
the table fields are
username nvarchar
startdate datetime
enddate datetime
paytype int
reminder int
while registering the user will selects the startdate and enddate and the pay type is 6months or 1year and he will select the reminder before 10days
then if he selects for 6months then before 10days i have to send email. if he selects for 1year i have to send for every 6months before 10 days
then how to write the querry for this condition please give the example which helps me.
|
|
|
|
|
developerit wrote: then how to write the querry for this condition please give the example which helps me.
You'll need to write a SELECT [^] statement, with a filter on the EndDate .
You'd have to compare whether this EndDate equals "today" + 10 days. You can get todays date by using the GETDATE() [^]-function, and add 10 days using the DATEADD [^] function.
Good luck
I are Troll
|
|
|
|
|
Most of the time there are two/three record in the table.
How can you do it in SQL
IF Status = 1 or status = 0 THEN Desc = "In Progress"
TabID Status
T1 1
T1 0
If Status = 1 or status = 1 THEN Desc = "Ok"
TabID Status
T1 1
T1 1
If status = 0 or status = 0 THEN Desc = "failed"
TabID Status
T1 0
T1 0
Select should give me 1 row only
My example is not correct, kindly enhance.
select tabid, GroupDesc = case when groupstatus = '1' or groupstatus = '0' then 'In Progress'
else 'Ok' end
from tab1
where tabid = T1
Dabsukol
|
|
|
|
|
Try this:
SELECT tableIdentity,
case when groupstatus = 1 or groupstatus = 0 then 'In Progress' else 'OK' end GroupDesc
from tableOne
where tabid = T1;
You should also physically confirm that you have only a single row named T1.
|
|
|
|
|
Select Min(Priority) from Outbox where [Transmitted] = false and [FolderId] IN (7,8) and
[Deleted] = false and [InterfaceNo] =@InterfaceNo and [SwitchingAddressNo] NOT IN
(Select [SwitchingAddressNo] from AddressBook where [Block] = true and [Deleted] = false
The above query i wrote, and its working fine.
I want to know the performance related issues with this?
If its ugly?
then how can i improve the same.
|
|
|
|
|
You are using NOT IN in you query, it is not good for the query performance as the query is not going to use benefits of indexes defined on the table and will use a sequential scan on the entire table, try to use NOT EXISTS .
WWW, WCF, WWF, WPF, WFC .... WTF
|
|
|
|
|
Does this apply to all DBs? I have never used NOT EXISTS...
Humble Programmer
|
|
|
|
|
I am sure about SQL Server, Oracle and Sybase but no idea about other DB servers.
WWW, WCF, WWF, WPF, WFC .... WTF
|
|
|
|
|
Indexes and Index Hints - possibly.
|
|
|
|
|
I have created a database with n number of tables. i want to delete some rows from some tables matching certain criteria. This i have to do dynamically. I am a beginner to sql. If someone in here can shed me a light will be great.
|
|
|
|
|
Something like:
delete from table where mycolumn = 0
The where is where you put conditional statements that match your requirement. So, for instance, let's say I have a person table and one of the columns tells me that a person is active or not I might use:
delete from person where IsActive = 0
me, me, me
"The dinosaurs became extinct because they didn't have a space program. And if we become extinct because we don't have a space program, it'll serve us right!"
Larry Niven
|
|
|
|
|
Do you mean that you want to delete the same information from multiple tables?
Humble Programmer
|
|
|
|
|
For some reason, my query causes a data type mismatch error due to where clause #5 below. I am not sure how this is possible given clause #2 & 3.
Where clauses
1) (NOT ID_BB_SEC_NUM_DES IS NULL AND TYPENAME(ID_BB_SEC_NUM_DES)='String')
2) AND (LEN(ID_BB_SEC_NUM_DES) BETWEEN 9 AND 13)
3) AND ( RIGHT(ID_BB_SEC_NUM_DES, 1) IN ('W', 'M', 'Y') )
4) AND ( LEFT( RIGHT( RIGHT( ID_BB_SEC_NUM_DES, LEN( ID_BB_SEC_NUM_DES )-6 ), 3), 1) IN ('B','R','V') OR LEFT( RIGHT( RIGHT( ID_BB_SEC_NUM_DES, LEN( ID_BB_SEC_NUM_DES )-6 ), 4), 1) IN ('B','R','V') )
5) AND ( INSTR( RIGHT(ID_BB_SEC_NUM_DES, LEN(ID_BB_SEC_NUM_DES)-6), 'O')=0)
|
|
|
|
|
I'm not familiar with INSTR, and googling SQL instr function told me its semantics depend on the database one uses. I guess that is where the problem originates.
|
|
|
|