Question

Im using Delphi XE2 and SQL Server 2005 Express.

I have a table named maintenance with the columns:

id Integer;
Activity Varchar(x); = actividad
Description Memo; = descripcion
Day Integer;= dia_sem
User Integer; = usuario

id, activity, description, day, user

I use this table to register the activities of maintenance that have to be donne in each day, as in Monday they have to clean behind x or y etc, on tuesdays they have to do something else etc.

I save the day from 1 to 7 being Sunday=1 to Saturday=7, so the program will retrieve all the activities where queryday.text= DayOfWeek(Now) and warn the users that there are activities to be donne.

My problem is that i want to show in a DBGrid the day with the full name and not as a number.

Sunday
Monday 
Tuesday etc.

On SQL i get the full day name using:

Select id AS ID, actividad AS Actividad, descripcion AS Descripcion,(datename(weekday, dia_sem-2)) AS Dia, usuario AS Usuario
from mantenimiento

i set dia_sem-2 so it would match the day i want (Apparently Tuesday=1)

My problem is that when i add this query to a Tquery on delphi and i add the fields, the "day" field is not added, it doesnt exist. What am I doing wrong or how can i achieve what im trying to do?.

Was it helpful?

Solution

Did you say tQuery? If I remember correctly, tQuery is a BDE component. The BDE is obsolete technology and using a more modern method of connecting to your database would be recommended.

That being said, the BDE doesn't know how to deal with Unicode string datatype. (I'm not sure Unicode even existed when the BDE was first made.)

The type returned from the SQL Server function DateName is nvarchar. The 'n' means that it's a Unicode string.

As a workaround you can cast the result to an Ascii string. Try something like this:

cast ( datename(...) as varchar(20))

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top