|
Hi,
I have table with 5 column I need to group the duplicate recorde and sum the quantity. And this my table column
Product Quantity price description
How can i do that?
Thank you
sms
|
|
|
|
|
webhay wrote: I need to group the duplicate recorde and sum the quantity. And this my table column
Product Quantity price description
How can i do that?
Select Product, SUM(Quantity) Quantity From tblProducts Group By Product
Regards J O H N
"Even eagles need a push." David McNally
|
|
|
|
|
Hi everyone.
I want to know from you guys what approach you're using to persist an object into the SQL Server database?
I and some work mates are discussing about the best approach of doing this for our next project, but we don't have much information or experience about the subject, so any information would be welcomed.
Thanks in advance
|
|
|
|
|
pontonet wrote: I want to know from you guys what approach you're using to persist an object into the SQL Server database?
INSERT statements usually do it for me.
I think you need to provide more detail. For example, are you talking about ORM? Just any type of object? Or do you need to turn an existing object model in to a relational model?
|
|
|
|
|
I meant better approaches, for instance, NHibernate, and so on.
Technologies that does it almost automatically for you, without needing to write much SQL code directly.
|
|
|
|
|
pontonet wrote: I meant better approaches, for instance, NHibernate, and so on.
ORM tools then.
pontonet wrote: Technologies that does it almost automatically for you, without needing to write much SQL code directly.
Ah, well... Can't help you if you are looking for ORM tools. I'm a big fan of creating stored procedures and a DAL that is a proxy for the stored procedure. I don't advocate exposing tables directly on the grounds that it is a security risk.
Although, having said that some ORM tools do make better allowances for stored procedures LLBLGen I believe is one.
|
|
|
|
|
Could somebody kindly tell me what the object reference in Microsoft Access is for the Common Dialog box for the Open File Dialog? The code that I have is as follows:
Private Sub cmdOutputFilePath_Click()
'The error message is a compiler error stating 'User-defined type not defined'
Dim dlgLoadOutputFilePath As FileDialog
Set dlgLoadOutputFilePath = Application.FileDialog( _
FileDialogType:=msoFileDialogOpen)
With dlgLoadOutputFilePath
.AllowMultiSelect = False
.Show
End With
If txtInputFilePath.Value = Null Then
txtOutputFilePath = ""
txtInputFilePath.SetFocus
Else
prgProgressBar.Value = 20
txtMessageBoxText.SetFocus
txtMessageBoxText.Text = "<Message>"
End If
End Sub
|
|
|
|
|
I would like to be able to add a field to an existing table in Microsoft Access. It is my understanding that I would need to use a TableDef object. Could you give me some insights? The code I have now is like so:
Option Compare Database
Public dbsHeadcount As Database
Public Cnxn As ADODB.Connection
Public rstHyperionMany As ADODB.Recordset
Function ProcessHeadcountFile()
On Error GoTo ErrorHandler
Dim strConn As String
Dim rstLoadFile As ADODB.Recordset
Dim cmdSQLLoadFile As ADODB.Command
Dim strSQLLoadFile As String
Dim rstHyperionOne As ADODB.Recordset
Dim cmdSQLHyperionOne As ADODB.Command
Dim strSQLHyperionOne As String
Dim cmdSQLHyperionMany As ADODB.Command
Dim strSQLHyperionMany As String
Dim strFileName As String
Dim qdfTemp As QueryDef
Dim qdfNew As QueryDef
Dim strHoldRecString As String
Dim strMessage As String
Set dbsHeadcount = OpenDatabase("J:\<FILEPATH>\Headcount Database.mdb")
Set Cnxn = New ADODB.Connection
strConn = "Provider=Microsoft.Jet.OLEDB.4.0; " & _
"Data Source=J:\<FILEPATH>\Headcount Database.mdb;"
Cnxn.Open strConn
Call LoadExcelIntoAccessTable
Set cmdSQLInputFile = New ADODB.Command
Set cmdSQLInputFile.ActiveConnection = Cnxn
Set cmdSQLHyperionMany = New ADODB.Command
Set cmdSQLHyperionMany.ActiveConnection = Cnxn
strSQLHyperionMany = "SELECT [COUNTRY], [TYPE], [BUSINESS UNIT], " & _
"[L/R/G], [REGION], [JOB FUNCTION], [09/12/2007 Reported] " & _
"FROM [tblInputFile]"
cmdSQLHyperionMany.CommandType = adCmdText
cmdSQLHyperionMany.CommandText = strSQLHyperionMany
Set rstHyperionMany = cmdSQLHyperionMany.Execute()
rstHyperionMany.MoveFirst
Call CreateIndexesForLoadedTable
ErrorHandler:
If Err <> 0 Then
MsgBox Err.Source & ":" & Err.Description, , "Error and Error #" & Err.Number
End If
End Function
Sub LoadExcelIntoAccessTable()
DoCmd.TransferSpreadsheet acImport, acSpreadsheetTypeExcel9, _
"tblInputFile", "C:/Employees.xls", True
End Sub
Sub CreateIndexesForLoadedTable()
Dim tdfInputFile As TableDef
Set tdfInputFile = dbsHeadcount.CreateTableDef("tblInputFile")
tdfInputFile.Fields.Append tdfInputFile.CreateField("Date", dbDate)
dbsHeadcount.TableDefs.Append tdfInputFile
ERROR: Here is where it is saying that tblInputFile already exists. How do I append the field called "Date" to the existing table called tblInputFile??????????? :confused::confused::confused:
End Sub
|
|
|
|
|
I have a storedProcedure i need to modify so it can sort by one of two columns, i need to allow the program calling the stored procedure to choose which one it wants the data sorted by, currently there are serveral if statments deciding exactly which select statment i will run, i need all of them to have the order by on the end as a variable passed into the stored procedure, is there any way to do this?
my last try:
if @Filter = 'All' and @DateFrom is Null and @MatterRef = ''<br />
BEGIN<br />
select * <br />
from undertakings <br />
order by <br />
case <br />
when @sortBy = 'matterRef' then undertakings.MatterRef<br />
when @sortBy = 'Date' then undertakings.DateTaken<br />
end<br />
END<br />
if @filter = 'Active' and @DateFrom is Null and @MatterRef = ''<br />
BEGIN<br />
select * <br />
from undertakings <br />
where Discharged = 0 <br />
order by <br />
case <br />
when @sortBy = 'matterRef' then undertakings.MatterRef<br />
when @sortBy = 'Date' then undertakings.DateTaken<br />
end<br />
END<br />
if @Filter = 'Discharged' and @DateFrom is Null and @MatterRef = ''<br />
BEGIN<br />
select * <br />
from undertakings <br />
where Discharged = 1 <br />
order by <br />
case <br />
when @sortBy = 'matterRef' then undertakings.MatterRef<br />
when @sortBy = 'Date' then undertakings.DateTaken<br />
end<br />
END
the procedure is a little more complex, with several other condtions but you should be able to get the idea.
Any help or pointers would be appreciated
|
|
|
|
|
when you have more than one filter criteria It's always a good practice to do it in a single dynamic query (T-Sql String). sp_executesql command can be used to execute a string and also it support's substituting any paramerter values that is specified in T-Sql String. I have gone through your Query and written a stored procedure. Hope it will help you to modify your's...
Create Procedure sp_undertakingsSelect
@Filter NVarchar(50),
@DateFrom DateTime,
@MatterRef NVarchar(200),
@sortBy NVarchar(50)
AS
Set NoCount ON
Declare @SQLQuery AS NVarchar(4000)
Declare @ParamDefinition AS NVarchar(2000)
Set @SQLQuery = 'Select * From undertakings where (1=1) '
If @Filter = 'Active'
Set @SQLQuery = @SQLQuery + ' And Discharged = 0'
If @Filter = 'Discharged'
Set @SQLQuery = @SQLQuery + ' And Discharged = 1'
If @DateFrom Is Not Null
Set @SQLQuery = @SQLQuery + ' And DateTaken >= @DateFrom'
If @MatterRef <> ''
Set @SQLQuery = @SQLQuery + ' And MatterRef LIKE '''+ '%' + @MatterRef + '%' + ''''
If @sortBy = 'matterRef'
Set @SQLQuery = @SQLQuery + ' Order By MatterRef '
If @sortBy = 'Date'
Set @SQLQuery = @SQLQuery + ' Order By DateTaken'
Set @ParamDefinition = '@Filter NVarchar(50),
@DateFrom DateTime,
@MatterRef NVarchar(200),
@sortBy NVarchar(50)'
Exec sp_Executesql @SQLQuery, @ParamDefinition, @Filter, @DateFrom, @MatterRef, @sortBy
If @@ERROR <> 0 GoTo ErrorHandler
Set NoCount OFF
Return(0)
ErrorHandler:
Return(@@ERROR)
GO
Regards J O H N
"Even eagles need a push." David McNally
|
|
|
|
|
Worked a treat, many thanks for taking the time to respond to my question.
|
|
|
|
|
Ed Hill _5_ wrote: many thanks
You're most welcome
Regards J O H N
"Even eagles need a push." David McNally
|
|
|
|
|
can i ask for the codes on "password problem" like what you have in your system. codes on how the user can retrieve his password if ever he forgot it. in php or sql codes please. with detailed instructions... thank you! More Power Guys!
|
|
|
|
|
If you are using .NET 2, use the Membership provider and let it take care of it all for you.
Deja View - the feeling that you've seen this post before.
|
|
|
|
|
LyndonJohn wrote: the codes on "password problem" like what you have in your system
All my code that deals with passwords stores them as salted hash values. You cannot retrieve passwords stored as a salted hash.
|
|
|
|
|
I hash my passwords with salted hashes, so there isn't any way to get it.
LyndonJohn wrote: how the user can retrieve his password if ever he forgot it.
The user shouldn't be using my software if he/she is retarded enough to lose their password. I do have admin tools that allow resets specific to my apps.
"Any sort of work in VB6 is bound to provide several WTF moments." - Christian Graus
|
|
|
|
|
Hi
Is it possible to write a query that will return the datatype of each field as opposed to actual data?
tks
Richard
|
|
|
|
|
Look at the INFORMATION_SCHEMA.COLUMNS to find the data type of columns in the database. (Assums SQL Server - You didn't say, but it is the most common database used on this forum)
|
|
|
|
|
Hi Colin
Yes Using SQL server, but how do I do this? I looked, but don't seem to find a table with this name (INFORMATION_SCHEMA.COLUMNS)?
|
|
|
|
|
RichardBerry wrote: Yes Using SQL server, but how do I do this? I looked, but don't seem to find a table with this name (INFORMATION_SCHEMA.COLUMNS)?
It is a view, not a table.
It is on the Master database and will be picked up regardless of which database you are in.
I'm also curious, did it not occur to you just to type SELECT * FROM INFORMATION_SCHEMA.COLUMNS or search for references to it on the internet?
|
|
|
|
|
Hi Colin
Thanks that was exactly what I was looking for.
Colin Angus Mackay wrote: I'm also curious, did it not occur to you just to type SELECT * FROM INFORMATION_SCHEMA.COLUMNS or search for references to it on the internet?
No it did not occur to me, since I looked through all the databases on the server, and could not find a table with that name, so I thought perhaps this was a table that was not in my database. I had never heard of a 'view' before, so I am currently GOOGLING 'SQL View' to learn more about that. It is sometimes difficult for a NOVICE (myself) to ask the right questions or look in the right places for information.
|
|
|
|
|
I use ExecuteReader and then ask the DataReader for the DataTypes.
DataReader.GetSchemaTable()
or
DataReader.GetFieldType()
|
|
|
|
|
RichardBerry wrote: Is it possible to write a query that will return the datatype of each field
In sql Server, there is a system stored procedure (sp_columns ) which returns column information for the specified table or view. You can execute that to get the DataType of the columns.
Exec sp_columns [@TableName]
Regards J O H N
"Even eagles need a push." David McNally
|
|
|
|
|
Hi John
Thanks for your reply. I tried running that stored procedure from MS Query, and get the following fields returned,but with no data.
TABLE_QUALIFIER, TABLE_OWNER, TABLE_NAME, COLUMN_NAME, DATA_TYPE..... Etc
It would actually be great if I could get all table data for the database in the above format.
When executing 'Exec sp_columns [@TableName]' I tried replacing 'TableName' with various strings but cant seem to get any data back. I tried *, vektron.scheme.units, scheme.units, units. But none seemed to work. Typically to execute a normal Select query, I would use:
SELECT * FROM vektron.scheme.units
Any idea what I could be doing wrong?
|
|
|
|
|
RichardBerry wrote: I tried running that stored procedure from MS Query, and get the following fields returned,but with no data.
return's no data? How come? It works fine in my system...
I have a table with the name tblProducts and I executed the stored proc as below...It return's the complete information...
Exec sp_columns [tblProducts]
Regards J O H N
"Even eagles need a push." David McNally
|
|
|
|