Showing posts with label complex. Show all posts
Showing posts with label complex. Show all posts

Friday, March 23, 2012

Retrieving the First N Records from a SQL Query in VS 2005

Hi,

first off, I'm a TOTAL novice at this stuff, I'm just currently blundering my way through a complex site to learn stuff.

I'm trying to call the newest addition to a SQL database into a webpage, in this case, it'll be 'newest user', one result only. I've done several other data retrival sections using a datatable, but the guy who was helping me though it is unavailable at the moment and I get the feeling I've jumped into the deepend slightly.

Could anyone give me an example of how retrieving the First N Records from SQL should look in VS? Does it need to be in a data table or can it go in a label?

Sorry if this is somewhat vague, but as I said, I've really only been using VS for a week!

SELECT TOP 1 FROM [TableName] ORDER BY timestamp

Hope this helps

Al

|||

Hi,

Using the Top keyword is the solution. But the use of TOP has changed between SQL2K and SQL2K5.

In SQL2k you were not able to use TOP @.N which means you can not dynamically set the record count for "TOP"

Check the article for TOP @.N usage athttp://kodyaz.com/articles/article.aspx?articleid=2

Also have a look at the new t-sql functions named "Window Functions". Also you can find some samples athttp://kodyaz.com/articles/article.aspx?articleid=19

Eralper

http://www.eralper.com

|||

Cheers Al,

trouble is, I'm unsure as to where it needs to go! As I said, I'm pretty rubbish at this VS lark so far.

Should I be using a datatable to display the information, or because its only a single result I want pulling back, can it be done in a label?

Currently, I have this working to bring back a compleate list of users, but on another page, I need to bring back only the newest. Once again, sorry if I appear dense, learning curve and all that;


CODE:

Dim SiteuserAsNew mySite.Siteuser

dlDataList.DataSource = Siteuser.List

dlDataList.DataBind()

HTML:

<asp:DataListID="dlDataList"runat="server">

<ItemTemplate>

<asp:LabelID="HyperLink1"runat="server"NavigateUrl='<%#Eval("SiteuserID", "viewuser.aspx?SiteuserID={0}" ) %>'Text='<%#Eval("title") %>'Font-Italic="true"></asp:Label><asp:HyperLinkID="hlkUser"runat="server"NavigateUrl='<%#Eval("SiteuserID", "viewuser.aspx?SiteuserID={0}" ) %>'Text='<%#Eval("fullname") %>'></asp:HyperLink></tr>

</ItemTemplate>

</asp:DataList>

sql

Wednesday, March 7, 2012

Retrieve Query

Hi Friends,
I had written a complex SQL query through SQL Query Analyzer, and had
executed the same by pressing F5 button. Before I could save that query on my
PC, my computer switched off.
By any chance is it possible to retrieve the complex query executed by me ?
If yes then how ?
Thanks and Regards,
AmitUnfortunately, you will have to use your skills to recreate that query. QA
does not have to ability, like the browser, to 'remember' the last thing we
typed in.
Be sure that you have that auto-shut down mechanism turned off next time. I
would absolutely hate it if "my computer switched off" without my telling to
it to do so.
--
Arnie Rowland
"To be successful, your heart must accompany your knowledge."
"Amit20" <Amit20@.discussions.microsoft.com> wrote in message
news:B7C8A4E4-3B96-4541-AA99-0F1EF2828B77@.microsoft.com...
> Hi Friends,
> I had written a complex SQL query through SQL Query Analyzer, and had
> executed the same by pressing F5 button. Before I could save that query on
> my
> PC, my computer switched off.
> By any chance is it possible to retrieve the complex query executed by me
> ?
> If yes then how ?
> Thanks and Regards,
> Amit|||You can not get the query back once it's done running. But let's say while
the query was running your computer got shut down and you had an option to
connect through another machine to same SQL instance then you could use the
following to get the query:
DBCC InputBuffer(spid)
It displays only first 255 characters of your query...
Bob
"Arnie Rowland" wrote:
> Unfortunately, you will have to use your skills to recreate that query. QA
> does not have to ability, like the browser, to 'remember' the last thing we
> typed in.
> Be sure that you have that auto-shut down mechanism turned off next time. I
> would absolutely hate it if "my computer switched off" without my telling to
> it to do so.
> --
> Arnie Rowland
> "To be successful, your heart must accompany your knowledge."
>
> "Amit20" <Amit20@.discussions.microsoft.com> wrote in message
> news:B7C8A4E4-3B96-4541-AA99-0F1EF2828B77@.microsoft.com...
> > Hi Friends,
> >
> > I had written a complex SQL query through SQL Query Analyzer, and had
> > executed the same by pressing F5 button. Before I could save that query on
> > my
> > PC, my computer switched off.
> >
> > By any chance is it possible to retrieve the complex query executed by me
> > ?
> > If yes then how ?
> >
> > Thanks and Regards,
> > Amit
>
>|||Or profiler was running, or ...
But for all practical purposes, the OP is SOL.
--
Arnie Rowland
Most good judgment comes from experience.
Most experience comes from bad judgment.
- Anonymous
"Bob" <Bob@.discussions.microsoft.com> wrote in message
news:DC9E8CBA-5BD2-480C-8B53-E332F1CB3FEE@.microsoft.com...
> You can not get the query back once it's done running. But let's say while
> the query was running your computer got shut down and you had an option to
> connect through another machine to same SQL instance then you could use
> the
> following to get the query:
> DBCC InputBuffer(spid)
> It displays only first 255 characters of your query...
>
> Bob
> "Arnie Rowland" wrote:
>> Unfortunately, you will have to use your skills to recreate that query.
>> QA
>> does not have to ability, like the browser, to 'remember' the last thing
>> we
>> typed in.
>> Be sure that you have that auto-shut down mechanism turned off next time.
>> I
>> would absolutely hate it if "my computer switched off" without my telling
>> to
>> it to do so.
>> --
>> Arnie Rowland
>> "To be successful, your heart must accompany your knowledge."
>>
>> "Amit20" <Amit20@.discussions.microsoft.com> wrote in message
>> news:B7C8A4E4-3B96-4541-AA99-0F1EF2828B77@.microsoft.com...
>> > Hi Friends,
>> >
>> > I had written a complex SQL query through SQL Query Analyzer, and had
>> > executed the same by pressing F5 button. Before I could save that query
>> > on
>> > my
>> > PC, my computer switched off.
>> >
>> > By any chance is it possible to retrieve the complex query executed by
>> > me
>> > ?
>> > If yes then how ?
>> >
>> > Thanks and Regards,
>> > Amit
>>

Retrieve Query

Hi Friends,
I had written a complex SQL query through SQL Query Analyzer, and had
executed the same by pressing F5 button. Before I could save that query on m
y
PC, my computer switched off.
By any chance is it possible to retrieve the complex query executed by me ?
If yes then how ?
Thanks and Regards,
AmitUnfortunately, you will have to use your skills to recreate that query. QA
does not have to ability, like the browser, to 'remember' the last thing we
typed in.
Be sure that you have that auto-shut down mechanism turned off next time. I
would absolutely hate it if "my computer switched off" without my telling to
it to do so.
Arnie Rowland
"To be successful, your heart must accompany your knowledge."
"Amit20" <Amit20@.discussions.microsoft.com> wrote in message
news:B7C8A4E4-3B96-4541-AA99-0F1EF2828B77@.microsoft.com...
> Hi Friends,
> I had written a complex SQL query through SQL Query Analyzer, and had
> executed the same by pressing F5 button. Before I could save that query on
> my
> PC, my computer switched off.
> By any chance is it possible to retrieve the complex query executed by me
> ?
> If yes then how ?
> Thanks and Regards,
> Amit|||You can not get the query back once it's done running. But let's say while
the query was running your computer got shut down and you had an option to
connect through another machine to same SQL instance then you could use the
following to get the query:
DBCC InputBuffer(spid)
It displays only first 255 characters of your query...
Bob
"Arnie Rowland" wrote:

> Unfortunately, you will have to use your skills to recreate that query. QA
> does not have to ability, like the browser, to 'remember' the last thing w
e
> typed in.
> Be sure that you have that auto-shut down mechanism turned off next time.
I
> would absolutely hate it if "my computer switched off" without my telling
to
> it to do so.
> --
> Arnie Rowland
> "To be successful, your heart must accompany your knowledge."
>
> "Amit20" <Amit20@.discussions.microsoft.com> wrote in message
> news:B7C8A4E4-3B96-4541-AA99-0F1EF2828B77@.microsoft.com...
>
>|||Or profiler was running, or ...
But for all practical purposes, the OP is SOL.
Arnie Rowland
Most good judgment comes from experience.
Most experience comes from bad judgment.
- Anonymous
"Bob" <Bob@.discussions.microsoft.com> wrote in message
news:DC9E8CBA-5BD2-480C-8B53-E332F1CB3FEE@.microsoft.com...[vbcol=seagreen]
> You can not get the query back once it's done running. But let's say while
> the query was running your computer got shut down and you had an option to
> connect through another machine to same SQL instance then you could use
> the
> following to get the query:
> DBCC InputBuffer(spid)
> It displays only first 255 characters of your query...
>
> Bob
> "Arnie Rowland" wrote:
>