|
Would be nice to pickup the first record from a sorted view. Something like:
Select Top(1) ID, UTCDateTime, Value
From TableName
OrderBy Value Desc
Syed Mehroz Alam
|
|
|
|
|
if you really want to do it that way you can do
SELECT TOP 1 MAX(value) as MyValue, UTCDateTime
FROM TableName
GROUP BY UTCDateTime
you have to have the top 1 otherwise you will get all of the max values for every dateTime, in descending order..
Please remember to rate helpful or unhelpful answers, it lets us and people reading the forums know if our answers are any good.
|
|
|
|
|
Thanks for the replys but....
Both of these examples only return the first record it finds not the largest value
meh
|
|
|
|
|
Post your data how is stored on table and post result which you want to get.
I Love T-SQL
"Don't torture yourself,let the life to do it for you."
|
|
|
|
|
This seems to work....I jusk stumbling around until this happened.....
SELECT ActualValue, UTCDateTime
FROM dbo.tblActualValueFloat
WHERE (ActualValue = (SELECT MAX(ActualValue) AS Expr1
FROM dbo.tblActualValueFloat AS tblActualValueFloat_1
WHERE (PointSliceID = '782') AND (UTCDateTime - 0.167 > '5/1/2008')
AND (UTCDateTime - 0.167 < '6 / 1 / 2008'))) AND (PointSliceID = '782')
AND (UTCDateTime - 0.167 > '5 / 1 / 2008') AND (UTCDateTime - 0.167 < '6 / 1 / 2008')
I know there are some hard coded test variables but this seems to be working for now.
Thanks to all
meh
|
|
|
|
|
Hi all,
Please help me with the below sql query
I am having 4 tables
SML,SMG,SMS,TKM
I have to retrive records
2 columns from table SML
1 columns from table SMS(the mapping from table SML and SMS is through SMG for eg: using the foreignid of SMG in SML we get the foreignid of SMS in the table SMG, using this i have to get the column from the table SMS)
1 column from table TKM (the mapping is SMS and TKM directly using the foreignid of TKM in the table SML)
Table SML:
ID Name idSMG IDTKM
Table SMG
ID idSMS
Table SMS
ID Name
Table TKM
ID Name
Thanks in advance
Know is Drop, Unknown is Ocean
|
|
|
|
|
What have you come up with so far?
"The clue train passed his station without stopping." - John Simmons / outlaw programmer
"Real programmers just throw a bunch of 1s and 0s at the computer to see what sticks" - Pete O'Hanlon
|
|
|
|
|
Hi,I am new comer of sql server2005.How can I know the database version through query.Pls help me
|
|
|
|
|
SELECT @@VERSION
Next time i will not give you an Answer, you must First Google before you post here on the Forum.
Vuyiswa Maseko,
Sorrow is Better than Laughter, it may Sadden your Face, but It sharpens your Understanding
VB.NET/SQL7/2000/2005
http://vuyiswamb.007ihost.com
http://Ecadre.007ihost.com
vuyiswam@tshwane.gov.za
|
|
|
|
|
I know this query.By this I know the version of sql server.Can I know the version of master database or user create database version.
|
|
|
|
|
hi I dont Understand what you want.
Forum: SQL and Database discussions
Subject: Re: Know the Database version
Sender: Sritanu _ Ghosh
Date: Friday, August 1, 2008 2:46 PM
Does a Database have a Version ?
Am not sure what you want. ok
Vuyiswa Maseko,
Sorrow is Better than Laughter, it may Sadden your Face, but It sharpens your Understanding
VB.NET/SQL7/2000/2005
http://vuyiswamb.007ihost.com
http://Ecadre.007ihost.com
vuyiswam@tshwane.gov.za
|
|
|
|
|
Vuyiswa Maseko wrote: Does a Database have a Version ?
I think he wanted to ask the compatibility level(SQL 7.0/2000/2005 etc).
Here's the GUI process:
In the management studio, right click on the db -> select Properties -> click on Options -> the Compatibility Level is displayed along with the collation and recovery model.
But I dont know how to retrieve it using T-SQL.
Syed Mehroz Alam.
|
|
|
|
|
i was Suprised , lets hear if this solves his Problem.
Thanks
Vuyiswa Maseko,
Sorrow is Better than Laughter, it may Sadden your Face, but It sharpens your Understanding
VB.NET/SQL7/2000/2005
http://vuyiswamb.007ihost.com
http://Ecadre.007ihost.com
vuyiswam@tshwane.gov.za
|
|
|
|
|
Is this what you are looking for ?
SELECT name, compatibility_level FROM sys.databases
Please... SAVE my time by rating the posts that you read!
There are 10 kinds of people in the world: those who understand binary and those who don't.
|
|
|
|
|
Please help...
Is there a way when I use initcap to make any letters displayed after an apostrophe be lowercase?
thanks in advance!
|
|
|
|
|
Please i need help...
Can somebody explain me how can i implement an insertion trigger that inserts in another table.
Like i have one table wich i want to insert a new record but when i insert a record in the first table the same record must be inserted in an another table for security...
By the way im using sql server 2000 in this project.
Thanks
Sorry about the english, i speack portuguese ....
Just learning
|
|
|
|
|
Hi,
You would need something like this:
CREATE TRIGGER Duplicate ON TableName
AFTER INSERT AS
INSERT INTO AnotherTable (Column1, Column2...) SELECT Column1, Column2... FROM inserted
END
Mika
|
|
|
|
|
Oi,
Eu já fiz algumas bases de dados e nunca precisei á data, de usar triggers (em sql).
Mas queres inserir dados ao mesmo tempo em duas tabelas? Porque não fazes isso com uma store procedure normal, achas que não dá para isso?!
O que tens na ideia? talvez te possa ajudar.
|
|
|
|
|
|
We need to know what the data looks like in your file and exactly what you want when you are done with your query. It sounds like you do not have much experience with SQL so I'd suggest taking a look at some of these sites to get some basic knowledge:
SQL Tutorial[^]
SQL.org[^]
Another Tutorial[^]
Google list[^]
|
|
|
|
|
I'm having some issues with a Query I'm trying to use to fine similar records in a master table. There are several child tables that will be searched in a similar way. Basically, if there are more than two matches in the sub query I want to display those records.
Can anyone point me in the right direction to get this query to work? I understand why I can't use more than one field in my subquery but I can't think of another way to do this.
SELECT *
FROM UC
WHERE uc_key IN (SELECT mo_Key, COUNT(mo_key) as KeyCount
FROM MO
WHERE (mo_MoKey = @Key1 AND mo_Value = @Value1) OR (mo_MoKey = @Key2 AND mo_Value = @Value2) <- there will be a variable number of these that get generated programatically
AND KeyCount > 2)
(note, the table names have been mangled to protect the innocent)
Thanks, any ideas are appreciated.
|
|
|
|
|
You probably still want a JOIN; avoid using IN for anything other than literal lists.
|
|
|
|
|
Using a JOIN will improve speed?
|
|
|
|
|
It has in my experience. And much more flexible.
|
|
|
|
|
I'll have to experiment in that direction then. This is a nasty complicated app and I'll need all the little speed boosts I can get.
Thanks!
|
|
|
|