What is the SQL to get the first val in a column in a table?
I want to refactor this code, because it seems wasteful and wacky and weird:
public string getVersion()
{
try
{
string dynSQL = "SELECT * FROM invHeader";
DataSet workSites = dbconn.getDataSet(dynSQL);
//Go thru dataset and display the working files
//Only need one, although we'll be duplicating the version
//per each site as a check value during upgrades
//return workSites.Tables[0].Rows
foreach (DataRow row in workSites.Tables[0].Rows)
{
sVersion = row["ID"].ToString();
break;
}
}
catch (Exception ex)
{
Duckbill.ExceptionHandler(ex, "InvHeader.getVersion");
}
return sVersion;
} // getVersion
I was thinking I could change it to something like this:
public string getVersion()
{
try
{
string dynSQL = "SELECT FIRST ID FROM invHeader"; // I also tried
"SELECT 1 ID FROM invHeader"
DataSet workSites = dbconn.getDataSet(dynSQL);
return workSites.Tables[0].Rows[0];
}
catch (Exception ex)
{
Platypus.ExceptionHandler(ex, "InvHeader.getVersion");
}
} // getVersion
...but neither query returned what I want (the value of ID in the first
row). So what is the SQL to do that.
BTW, I know this should be some sort of scalar call, but so many funky
Rube Goldbergesque things happen in these homegrown, self-rolled methods
that rely on each other, I'm afraid to touch that; this little cleanup
should be doable without quaking in my booties, though.
UPDATE
I guess I jumped the gun awarding the answer - "SELECT TOP 1 ID FROM
invHeader" in SQL Server CE Query Analyzer results in:
FAILED: SELECT TOP 1 ID FROM invHeader
Error: x800...._E_ERRORSINCOMMAND
Native Error: (25501)
Description: There was an error parsing the query. [Token line number,
Token line offset, Token in error,,]
Interface defining error: IID_ICommand
Paaram. 0:1
Param. 1: 8
Param. 2:0
Param. 3: TOP
Param. 4:
Param. 5:
This seems cryptic as all get-out, but one thing I do grok is that SQL
Server CE Query Analyzer is "not amused."
No comments:
Post a Comment