Showing posts with label solution. Show all posts
Showing posts with label solution. Show all posts

Friday, March 23, 2012

How could I return the next row(Or 8th row for example)

Hi,
I want to return the next row in a select ... order by ... cursor.
I don't want to loop,just SQL,Do you know any solution?
For example: in Oracle we use rownum,is there any equivalent in SQL Server?
-ThanksWhy don't you explain why you think you need a cursor? In Oracle cursors are required, but with SQL Server they are considered inefficent and are rarely used.|||Thanks blindman ,
Typical scenario may be looks like this: I return the result of a heavy select(think about many joins and ...) to the client application: I want just one row at this stage. The application processes that row and then it needs the next row in that select to process.How should I say: "The next row in that select"?
One solution: Use a table (maybe temporary table) to hold the result of that select with an identity column as the rownum of each row.
Another solution: Hold the result of select in application layer and go through a loop in application to fetch the next row.
I am just curious about how one could do this in an "on the fly" manner? You are right maybe it is not efficient in SQL Server but is there any way at all?
-Regards|||Well, I think you should hold the data in the application layer if you want to ensure a static dataset for processing. Problem is, if you go back to SQL Server for your "next" record, the underlying data may have changed. Is your application modifying the data and sending it back to SQL server to be updated?|||Is your application modifying the data and sending it back to SQL server to be updated?
No,it is not.So there is no phantom read problem.I think this is so inefficient to pull all data to client-side only because you may want the next row.Are you in agreement? SQL Server should think about this carefuly,IMHO!
-Thanks|||Well you may think that, but it doesn't, not in SQL 2K.

2k5 will have rownumber if I'm not mistaken...

But this is the best server side paging articles I've seen

http://weblogs.sqlteam.com/jeffs/archive/2004/03/22/1085.aspx

And

http://weblogs.sqlteam.com/jeffs/archive/2003/12/22/672.aspx|||No,it is not.So there is no phantom read problem.I think this is so inefficient to pull all data to client-side only because you may want the next row.Are you in agreement? SQL Server should think about this carefuly,IMHO!
-Thanks
No, I'm not in agreement. How the data is displayed is up to the presentation layer and/or middle tier, and is not the database's responsibility. If the application demands paging, then the database needs to be DESIGNED to facilitate paging. Even ROWNUMBER is meaningless for repeated calls on dynamic datasets.|||How the data is displayed is up to the presentation layer and/or middle tier, and is not the database's responsibility.
OK,I am in agreement.Maybe this is about "Presentation of Data" but we know there is not a clear line between those layers: Many things can be done in Database layer but is implemented in "Application server or middle layer" and vice versa.
Thanks to your posts but I still think it is inefficient to pull whole data between layers and I became so happy when I heard that Yukon will have rownum from Brett.Thanks!|||I'd say use the system the way it was designed. Most of your time is not going to be pulling back an entire dataset, but cycling through it row by row. Databases are designed to work on results sets (i.e., not row by row) and thus aren't very efficient when you want to do that. However, procedural languages are designed to do that very thing. By way of example, I had a cursor running on the database when I first began posting here that took approximately 15 minutes to run. Through the help of those more knowledgable here, I was able to remove the cursor and get the same results in under 30 seconds. I guess the best way to test it is do it both ways, but I'm willing to bet you'll find that pulling the entire result set back and cycling in the app will be faster than coding a cursor in the database. Just my thoughts.

Wednesday, March 21, 2012

How check the results of the SQL Backups on serveral servers

Hi, I'm looking for a simple an easy solution to check the sqlserver backups
,
every day we run some backups jobs in diferent servers. How i can verify the
backup jobs everyday without check the enterprise manager of ervery server?
Is posible create a report where the copys are succesfuly per server and per
sql server database?
Thanks in advance
Fernando... Or use xp_smtp_sendmail and remove xp_sendmail and create a version of
xp_sendmail which in turn
calls xp_smtp_sendmail. As described on www.sqldev.net.
Tibor Karaszi, SQL Server MVP
http://www.karaszi.com/sqlserver/default.asp
http://www.solidqualitylearning.com/
"Peter The Spate" <anonymous@.discussions.microsoft.com> wrote in message
news:092001c490db$294323c0$a401280a@.phx.gbl...[vbcol=seagreen]
> You could get SQL Server Agent to email you results of the
> backup, but that is dependant upon SQL Agent having a
> domain user id with a mailbox.
> Thanks
> Peter
> "There is no such thing as public opinion. There is only
> published opinion."
> Winston Churchill
>
> the sqlserver backups,
> How i can verify the
> of ervery server?
> per server and per

How check the results of the SQL Backups on serveral servers

Hi, I'm looking for a simple an easy solution to check the sqlserver backups,
every day we run some backups jobs in diferent servers. How i can verify the
backup jobs everyday without check the enterprise manager of ervery server?
Is posible create a report where the copys are succesfuly per server and per
sql server database?
Thanks in advance
FernandoYou could get SQL Server Agent to email you results of the
backup, but that is dependant upon SQL Agent having a
domain user id with a mailbox.
Thanks
Peter
"There is no such thing as public opinion. There is only
published opinion."
Winston Churchill
>--Original Message--
>Hi, I'm looking for a simple an easy solution to check
the sqlserver backups,
>every day we run some backups jobs in diferent servers.
How i can verify the
>backup jobs everyday without check the enterprise manager
of ervery server?
>Is posible create a report where the copys are succesfuly
per server and per
>sql server database?
>Thanks in advance
>Fernando
>.
>|||... Or use xp_smtp_sendmail and remove xp_sendmail and create a version of xp_sendmail which in turn
calls xp_smtp_sendmail. As described on www.sqldev.net.
--
Tibor Karaszi, SQL Server MVP
http://www.karaszi.com/sqlserver/default.asp
http://www.solidqualitylearning.com/
"Peter The Spate" <anonymous@.discussions.microsoft.com> wrote in message
news:092001c490db$294323c0$a401280a@.phx.gbl...
> You could get SQL Server Agent to email you results of the
> backup, but that is dependant upon SQL Agent having a
> domain user id with a mailbox.
> Thanks
> Peter
> "There is no such thing as public opinion. There is only
> published opinion."
> Winston Churchill
>
> >--Original Message--
> >Hi, I'm looking for a simple an easy solution to check
> the sqlserver backups,
> >every day we run some backups jobs in diferent servers.
> How i can verify the
> >backup jobs everyday without check the enterprise manager
> of ervery server?
> >Is posible create a report where the copys are succesfuly
> per server and per
> >sql server database?
> >
> >Thanks in advance
> >Fernando
> >.
> >

How check the results of the SQL Backups on serveral servers

Hi, I'm looking for a simple an easy solution to check the sqlserver backups,
every day we run some backups jobs in diferent servers. How i can verify the
backup jobs everyday without check the enterprise manager of ervery server?
Is posible create a report where the copys are succesfuly per server and per
sql server database?
Thanks in advance
Fernando
... Or use xp_smtp_sendmail and remove xp_sendmail and create a version of xp_sendmail which in turn
calls xp_smtp_sendmail. As described on www.sqldev.net.
Tibor Karaszi, SQL Server MVP
http://www.karaszi.com/sqlserver/default.asp
http://www.solidqualitylearning.com/
"Peter The Spate" <anonymous@.discussions.microsoft.com> wrote in message
news:092001c490db$294323c0$a401280a@.phx.gbl...[vbcol=seagreen]
> You could get SQL Server Agent to email you results of the
> backup, but that is dependant upon SQL Agent having a
> domain user id with a mailbox.
> Thanks
> Peter
> "There is no such thing as public opinion. There is only
> published opinion."
> Winston Churchill
>
> the sqlserver backups,
> How i can verify the
> of ervery server?
> per server and per

Sunday, February 19, 2012

how can I throw a custom error code?

I'm trying to run a DTS package, and cant find an easy direct way to run it. It seems like the easiest solution would be to throw a custom error- then the server notices the error and runs a custom job, and the custom job runs the DTS. This is a roundabout way, but seems like it would be the simplest solution.

Anyways, how do I throw the error in my code? Do I just write a throw 3829 statement?

Also maybe this is a very bad way to do this- any suggestions?

You can use dtsrun commandline utilitySmile Take a look at this link:

http://msdn.microsoft.com/library/default.asp?url=/library/en-us/coprompt/cp_dtsrun_95kp.asp

BTW, SQL provides a extended stored procedure xp_cmdshell to perform commandline tasks, so you can also call dtsrun utility in T-SQL:

exec('master..xp_cmdshell ''dtsrun -S iori\Athena -E -N test ''')

|||I saw that command line solution a while ago, but I was told that it isnt the best thing to do security wise.

I ended up finding DTS.Packages (DTS.Package dtsp = new DTS.Package();) which seems to work pretty well. The only problem is that the web account does not have the correct permissions. By enabling a trusted connection, and tweaking IIS, it now prompts the user for a username/pswd when they get to the site. If they enter in an account with the correct permissions, then they are able to run the DTS job.

Now I'm trying to get rid of this annoyance. Is it possible to somehow force a login to a specific trusted account? If not then I was thinking of trying to run a job that will just run the DTS package, but I don't know how to do that either. Any suggestions?