|
Another option would be to store the time as a number, and when you retrieve it from your database, you can format it in your own way. For example, I store time fields as 6 digit numbers. The first two digits for the hour (military time) the second two digits as minutes, and the last two digits as seconds. So when I store them to my data base I only have to take the datetime object and do this:
myDataBaseRow("myTimeColumn") = objDateTime.ToString("HHmmss")
I know this isn't what you asked for, but I thought another view point might be helpful.
|
|
|
|
|
Hi all,
I can able to fetch a single data from Sql and display it in the Excel sheet using Macro, this is the code.
I am getting in the Text Box:
sno = TextBox1.Text
When i am clicking the Ok button:
Query = "Select sname,scity from smaster where snum='" & sno & "'"
Set QueryRs = oConn.Execute(Query)
Sheet1.Cells(1, 1) = QueryRs("sname")
Sheet.Cells(1, 2) = QueryRs("scity")
Result:
Name, city displayed in the Excel sheet1
Now my problem is how to fetch multiple data and display (like how to use loop in it)
waiting for timely help
Tech_spidy
|
|
|
|
|
|
Hi
I have created one table in sql server as
sno name desc
5 suma dckdfjdskfldkf;dsf
3 suma lklkjdkjfkjfdjbbbbb
8 suma jsakdksladksadks
4 manu nsdskdjsdsadl
2 manu klswkqewr
1 manu shdjsdksd
like this....
now i want to dispaly one record fro each user (i.e the record which is having max sno for each user)
i.e
8 suma jsakdksladksadks
4 manu nsdskdjsdsadl
how to write query for this
plz help me
Thanks in advance
Haritha
|
|
|
|
|
Here is the bit that will get the highest sno for each user
SELECT MAX(sno) AS sno, name FROM MyTable GROUP BY name
Add that as a subquery and join on to it like another table. Like this:
SELECT s.sno, s.name, m.desc
FROM MyTable AS m
INNER JOIN (SELECT MAX(sno) AS sno, name FROM MyTable GROUP BY name) AS s
ON s.sno = m.sno AND s.name = m.name
Upcoming events:
* Glasgow: Mock Objects, SQL Server CLR Integration, Reporting Services, db4o, Dependency Injection with Spring ...
"I wouldn't say boo to a goose. I'm not a coward, I just realise that it would be largely pointless."
Ready to Give up - Your help will be much appreciated.
My website
|
|
|
|
|
for this you have to use corolated queries following the example
SELECT sno, name, desc FROM WHERE sno=(SELECT MAX(sno) FROM Thanks
Warm Regards
Prakash-B
|
|
|
|
|
PrakashBhaskar wrote: for this you have to use corolated queries following the example
SELECT sno, name, desc FROM <table name> WHERE sno=(SELECT MAX(sno) FROM <table mame)
I think ur problem has solved
That will return the row "8 suma jsakdksladksadks " only.
Upcoming events:
* Glasgow: Mock Objects, SQL Server CLR Integration, Reporting Services, db4o, Dependency Injection with Spring ...
"I wouldn't say boo to a goose. I'm not a coward, I just realise that it would be largely pointless."
Ready to Give up - Your help will be much appreciated.
My website
|
|
|
|
|
i am sorry i have mis-understood the question
Thanks
Warm Regards
Prakash-B
|
|
|
|
|
You can use following query
select max(no),name from trial1
group by name
If have any questions, thn let me know
|
|
|
|
|
d_d_jadhav wrote: You can use following query
select max(no),name from trial1
group by name
If have any questions, thn let me know
No, that will result in:
8 suma
only. Which does not match the output the OP requested.
Upcoming events:
* Glasgow: Mock Objects, SQL Server CLR Integration, Reporting Services, db4o, Dependency Injection with Spring ...
"I wouldn't say boo to a goose. I'm not a coward, I just realise that it would be largely pointless."
Ready to Give up - Your help will be much appreciated.
My website
|
|
|
|
|
You can use following query
select max(no),name from trial1
group by name
If have any questions, thn let me know
Dipti Jadhav
|
|
|
|
|
One post is enough.
Regards,
Satips.
Don't walk in front of me, I may not follow;
Don't walk behind me, I may not lead;
Walk beside me, and just be my friend. - Albert Camus
|
|
|
|
|
The answer for ur question is here
select sno,name,[desc] from trial1
where convert(varchar(50),sno)+name in(select convert(varchar(50),max(sno))+name from trial1
group by name)
Please let me know, if u have any questions/comments.
|
|
|
|
|
Its me again, i making a grade data entry. I have a database of diffenrent subjects. The fields that i will going to use is these: Subject code, Subject description, and professor.
What I want is to view the subject description and the professor in the textboxes when I select a subject code in the combo box.
I had already made an OleDbDataAdapter for that, and the subject codes was the data member in the combobox. The subject codes is already the item of the combobox but my problem is, the subject description and professor was not appeared in the textbox. What I want is this to view to its corresponding textboxes.
I used this code:
For ctr = 0 To DataSet31.studentsubjects.Rows.Count - 1<br />
dr = DataSet31.studentsubjects.Rows(ctr)<br />
If ComboBox1.SelectedItem = dr("subject") Then<br />
subjdesc.Text = dr("subjdesc")<br />
prof.Text = dr("professor")<br />
End If<br />
Next
Is the code above correct??? If its not, what is the right code????
Where will I going to put the codes???
|
|
|
|
|
Rharzkie wrote: ComboBox1
Can you please name your variables with good names rather than accept the defaults that Visual Studio gives you.
Rharzkie wrote: ComboBox1.SelectedItem = dr("subject")
What does ComboBox1.SelectedItem return? Put a break point down and see what value it is returning. Also it will aid the debugging process if you assign the result of method and property calls to something then test on the local variables - it will make it easier to see what is going on in the debugger.
Upcoming events:
* Glasgow: Mock Objects, SQL Server CLR Integration, Reporting Services, db4o, Dependency Injection with Spring ...
"I wouldn't say boo to a goose. I'm not a coward, I just realise that it would be largely pointless."
Ready to Give up - Your help will be much appreciated.
My website
|
|
|
|
|
The ComboBox1 is for the list of the subject code. I use the DISTINCT in query builder to display the items in the combobox. I use the OleDbDataAdapter1 for that.
But the connection that i will going to display in textbox is OleDbDataAdapter3. In short, i use different connection from the combobox and the textboxes. Is this correct?
|
|
|
|
|
Rharzkie wrote: The ComboBox1 is for the list of the subject code.
Yes, but ComboBox1 still isn't a good name for it, is it?
Rharzkie wrote: OleDbDataAdapter1
Rharzkie wrote: OleDbDataAdapter3
How do you keep track of what each of these does?
Rharzkie wrote: Is this correct?
I have no idea. This code is obviously a mess. My suggestion is to start by naming things properly. Then it might be an idea to create a DAL and remove all your database interaction out of the user interface classes. It might also be an idea to do what I asked in my previous post and answer the question I asked. ("What does ComboBox1.SelectedItem return?" - And I want actual values and object types, not what you think it should return)
Upcoming events:
* Glasgow: Mock Objects, SQL Server CLR Integration, Reporting Services, db4o, Dependency Injection with Spring ...
"I wouldn't say boo to a goose. I'm not a coward, I just realise that it would be largely pointless."
Ready to Give up - Your help will be much appreciated.
My website
|
|
|
|
|
I currently have an app up and running in .NET. We have just built the server for the app to run on but there seems to be a problem with some of the returned date formats within the app itself. I checked the original test db and the date format was english style 31/12/2007 but on the new database it was amercian style 12/31/2007. Is there a setting in SQL server 2005 that would aler this?
|
|
|
|
|
Dates are not stored any any locale dependent format. When you get data out the database you should get a DateTime object which you can then format as you need with ToString()
e.g. myDate.ToString("dd/MM/yyyy")
Upcoming events:
* Glasgow: Mock Objects, SQL Server CLR Integration, Reporting Services, db4o, Dependency Injection with Spring ...
"I wouldn't say boo to a goose. I'm not a coward, I just realise that it would be largely pointless."
Ready to Give up - Your help will be much appreciated.
My website
|
|
|
|
|
Hi,
Is there any query through which i can get the number of columns in a table.
Best Regards,
Mushq
Mushtaque Ahmed Nizamani
Software Engineer
Ultimus Pakistan
"English is my second language, so please don't mind if i do some grammatical or spelling mistakes in my messages."
|
|
|
|
|
SELECT Count(COLUMN_NAME)
FROM INFORMATION_SCHEMA.COLUMNS
WHERE TABLE_Name = 'TableName'
|
|
|
|
|
I try this code, and it's work.
select name,date=max(date),
sum(case when type='A' then value else 0 end) as 'A',
sum(case when type='B' then value else 0 end) as 'B',
sum(case when type='C' then value else 0 end) as 'C'
from table1
group by name
But after few days, my database is update with more than one record in the same name, separate by column name 'date',
Regarding I just want to display data depend on last date,
Example my table is below:
name type value date
-----------------------------------------------------
a A 1 07/10/2007
a B 1 07/10/2007
a C 1 07/10/2007
a A 2 07/13/2007
a B 2 07/13/2007
a C 2 07/13/2007
but the result is:
the result is:
name date A B C
-----------------------------------------
a 06/13/2007 3 3 3
I'm expecting like this:
name date A B C
-----------------------------------------
a 06/13/2007 2 2 2
I try to modified the code:
select name,
sum(case when type='A' and date=max(date) then....
but found error
So, any suggestion, thanks a lot.
|
|
|
|
|
Have you tried:
<code> select name,date,
sum(case when type='A' then value else 0 end) as 'A',
sum(case when type='B' then value else 0 end) as 'B',
sum(case when type='C' then value else 0 end) as 'C'
from table1 where date=max(date)
group by name </code>
"The clue train passed his station without stopping." - John Simmons / outlaw programmer
|
|
|
|
|
Are your sure and Have you checked is the query wroks.
Regards
KP
|
|
|
|
|
Krish - KP,
This one should do it. I created the same table you had, ran this one and it gives the right results
<code>select name,max(date),
sum(case when type='A' then value else 0 end) as 'A',
sum(case when type='B' then value else 0 end) as 'B',
sum(case when type='C' then value else 0 end) as 'C'
from table_1 where date=(select max(date) from table_1)
group by name </code>
"The clue train passed his station without stopping." - John Simmons / outlaw programmer
|
|
|
|
|