My following code is only retrives number month(1,2,3,4....12) and not month name(January,February,.....December). Can anyone help me to retrieves month name in sql query. Before that i had try using function datepart, Monthname and date_format but i still din get my answer.Thanks

con.ConnectionString = "PROVIDER=Microsoft.Jet.OLEDB.4.0;Data Source = C:\YS.mdb"
        con.Open()

        sql = "SELECT DISTINCT MONTH(dates) As [dates] FROM summary WHERE plants = '" & yieldsummary.cbPlant.Text & "' AND Year(dates) = " & cbYear.Text & "AND line = '" & cbLine.Text & "'"
        da = New OleDb.OleDbDataAdapter(sql, con)
        da.Fill(ds, "summary")

        con.Close()

Recommended Answers

All 4 Replies

Select Distinct DATENAME(mm, CONVERT(CHAR(19), [dates])) AS [dates] From....

That will fomat the name of the month to be returned. However concatenating query strings like that is very poor programming format. You should look into how to convert that and use parameters.

:(

I TRY the coding already but come out "Undefined function'DATENAME' in expression. So i am wonder why it is happen bacause last time i also got the same error.

DateName must be specific to Sql Server which im more familiar with. There should be an equivlant type function in Access, its just a matter of looking up the syntax in its help file.

Try this:

Select Distinct Format(dates, "mmmm") AS [dates] From...

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.