|
GuyThiebaut wrote: You may have to use a cursor.
Don't encourage people to use a cursor unless there is absolutely no other choice. Cursors are extremely slow in SQL Server and should be avoided unless absolutely necessary.
|
|
|
|
|
Ooh I feel like I have just been told off
What I have read in manuals is that cursors are generally very greedy in terms of resources.
My experience however has shown that they are perfectly fine to use.
Yes I know it is possible to write a query without the use of a cursor (I'll be damned if I know how to do this though).
I think unless the application is for some huge banking corporation or airline then using a cursor should be fine.
What would you suggest instead of cursors?
You always pass failure on the way to success.
|
|
|
|
|
GuyThiebaut wrote: Yes I know it is possible to write a query without the use of a cursor (I'll be damned if I know how to do this though).
You have to write a query to populate a cursor in the first place. Therefore you must know how to write some queries.
GuyThiebaut wrote: I think unless the application is for some huge banking corporation or airline then using a cursor should be fine.
That's your opinion, and I, along with many qualified DBAs that I know, disagree with it.
GuyThiebaut wrote: What would you suggest instead of cursors?
Write set based queries where possible. Never consider a cursor until all other avenues are exhausted.
SQL Server, along with many other RDBMS systems, works best when dealing with sets of data. It does not work well when dealing with individual rows.
SQL is a declarative language - you declare what you want and then leave it up to the database engine to figure out how to get it. When you use cursors you introduce an element of procedural programming in to it. That means you are forcing it to do it HOW you tell it, which is often not the best way.
There are some situations where CURSORs are needed, e.g. recursive data. But SQL Server 2005 and 2008 are eliminating those cases also with additions to SQL.
At the end of the day there is no single answer as to what you should replace a cursor with because there are many situations where they can be used when they shouldn't.
|
|
|
|
|
Okay - I agree with everything you say.
I have only used cursors where there is no other option, in my opinion, (having said that I have got a link somewhere on how to use a query to act as a cursor - it's rather esotric stuff though) so yes as you say I can generally write a query to avoid cursors.
I have tended to use them where I am piping data into a dts package that needs to be called once data has been aggregated for one group.
Regards
Guy
You always pass failure on the way to success.
|
|
|
|
|
Every day you post many questions that are easily answered via google. SQL Server also comes with very good documentation. If you don't learn to do basic research, you will never become a half decent developer.
Christian Graus - Microsoft MVP - C++
"I am working on a project that will convert a FORTRAN code to corresponding C++ code.I am not aware of FORTRAN syntax" ( spotted in the C++/CLI forum )
|
|
|
|
|
hello,
I need to store RTF (from a net richtext boxes RTF property) on an SQL table.
The size could be anything up to 16 or 17 Mb.
Whats the best datatype to use and has anyone got a codesnippet that could help.
if its something like binary then is it possible that I can search the field with a standard SQL statement such as in:
Select * where Fld Like "*Stuff to Find*"
Thanks in advance
Martin
life is a bowl of cherries
go on take a byte
|
|
|
|
|
MartyK2007 wrote: Whats the best datatype to use and has anyone got a codesnippet that could help.
If SQL Server 2000 then IMAGE
If SQL Server 2005 then VARBINARY(MAX)
Since RTF is contains text only with some crazy formatting instructions embedded in the text then you can also use TEXT , NTEXT , VARCHAR(MAX) or NVARCHAR(MAX) . The latter two in SQL Server 2005.
MartyK2007 wrote: if its something like binary then is it possible that I can search the field with a standard SQL statement such as in:
Select * where Fld Like "*Stuff to Find*"
I would look at Full text indexing for something like that.
|
|
|
|
|
dont I have to specify a MAX value though for
VARBINARY(MAX)
I wouldnt want to restrict the size if possible (other than database size limits of course)
thanks
Martin
life is a bowl of cherries
go on take a byte
|
|
|
|
|
ok stupid question - just googled VARBINARY(MAX)
thanks for that it seems to fit what I neeed
Martin
life is a bowl of cherries
go on take a byte
|
|
|
|
|
Hi,
This is regarding SQL Server 2005 Reporting Services.
I want t create virtual directories ('ReportServer','Reports') on IIS along with the deployment of my web application.How can i do that?.
Is it compolsury to create those two virtual directories via 'Reporting Service Configuration Tool' in advance?. Can't we create them as on own or by wep application setup? and then deploy our Reports?
please help me in this.
Thanks,
Karuna
Karuna
|
|
|
|
|
This question would fit more in ASP.NET forum. But anyway you can create the virtual directory on IIS when deploy your application by adding a custom action dll to the web setup project. The custom action should have the code to configure the directories as an application in IIS (i.e. as a virtual directory)
Below is some VB.NET code that you could have in your custom action project to configure 'Reports' directory as an application in IIS in the Root directory (i.e. Root - Default Web Site):
Dim IIsBOVirDirRootObj As Object = Nothing
Dim IIsWebVDirObj As Object = Nothing
' Create an instance of the virtual directory object
' that represents the virtual directory in the default Web site.
IIsBOVirDirRootObj = GetObject("IIS://localhost/W3SVC/1/Root")
Try
' Use the Windows ADSI container object "Create" method to create a new virtual directory.
IIsWebVDirObj = IIsBOVirDirRootObj.Create("IIsWebVirtualDir", "Reports")
Catch ex As Exception
End Try
You can use the same idea to create the virtual directory in the ReportServer Website
-- modified at 5:24 Tuesday 9th October, 2007
|
|
|
|
|
Hi,
I have a branch table. Besides the branch ID and branch name I have the following address fields:
AddressLine1
AddressLine2
AddressLine3
PostalCode
ProvinceID
These fields don't have to be inserted and can all be null. ProvinceID is a reference to the Province table. I have to join the tables and I need to bring back all the branches, if there is a link to the Province table or not. How will my JOIN section look like, and which JOIN will I need to make use of??
Please can someone advise.
Thanks
|
|
|
|
|
Asuming your is of SQL Server
for getting matching rows from both tables
SELECT <colum list> <br />
FROM Branch b<br />
INNER JOIN Province p ON b.ProvinceID = p.ProvinceID
for getting all rows from Branch table and matching rows from Province table
SELECT <colum list> <br />
FROM Branch b<br />
LEFT OUTER JOIN Province p ON b.ProvinceID = p.ProvinceID
for getting all rows from Province table and matching rows from Branch table
SELECT <colum list> <br />
FROM Branch b<br />
RIGHT OUTER JOIN Province p ON b.ProvinceID = p.ProvinceID
Regards
KP
|
|
|
|
|
Hi
SQL 2005Express[^] - is there a SQL Profiler (Not Query Analyzer which that comes with it? I don't think there is but where can I download one?
Thanks
|
|
|
|
|
http://sqlprofiler.googlepages.com/
|
|
|
|
|
I step through the code, and sometimes the code works, but then again, sometimes the code does not work. The error message I get is that "The Microsoft Jet database engine cannot find the input table or query 'qryPassThroughQuery'. Make sure it exists and that its name is spelled correctly."
I cannot understand it. On one occasion it will accept the record and pass through it without a problem. On another occasion, it does not accept it at all, providing this message. Could somebody please provide some advice???
Why can't the code find the query when the line practically in front of it does just that -- creates the query that it needs in that line???
Private Sub ProcessHeadcountRecords()
Dim Cnxn As ADODB.Connection
Dim strConn As String
Dim rstInputFile As ADODB.Recordset
Dim cmdSQLInputFile As ADODB.Command
Dim strSQLInputFile As String
Dim rstHyperionMany As ADODB.Recordset
Dim cmdSQLHyperionMany As ADODB.Command
Dim strSQLHyperionMany As String
Dim rstHyperionOne As ADODB.Recordset
Dim cmdSQLHyperionOne As ADODB.Command
Dim strSQLHyperionOne As String
Dim rstQueryDef As ADODB.Recordset
Dim strPassThroughQuery As String
Dim strDBPath As String
Dim strFileName As String
Dim strMessage As String
strDBPath = "J:\GELCO DATABASE\Headcount Database\Headcount Database.mdb"
Set dbsHeadcount = OpenDatabase(strDBPath)
Set Cnxn = New ADODB.Connection
strConn = "Provider=Microsoft.Jet.OLEDB.4.0; " & _
"Data Source=" & strDBPath & ""
Cnxn.Open strConn
Set rstInputFile = New ADODB.Recordset
strSQLInputFile = "SELECT [COUNTRY], [TYPE], [BUSINESS_UNIT], " & _
"[L_R_G], [REGION], [JOB_FUNCTION], [ACTUAL], [NUMINDEX] " & _
"FROM TBLINPUTFILE"
rstInputFile.Open strSQLInputFile, Cnxn, adOpenKeyset, adLockOptimistic
rstInputFile.MoveFirst
Set rstHyperionMany = New ADODB.Recordset
strSQLHyperionMany = "SELECT [COUNTRY], [TYPE], [BUSINESS_UNIT], " & _
"[L_R_G], [REGION], [JOB_FUNCTION], [NUMFOREIGNKEY] " & _
"FROM [TBLHYPERIONMANY2] ORDER BY [NUMFOREIGNKEY]"
rstHyperionMany.Open strSQLHyperionMany, Cnxn, adOpenKeyset, adLockOptimistic
strFileName = "qryPassThroughQuery"
txtMessageBoxText.SetFocus
txtMessageBoxText.Text = "Processing all the records from the upload file " & _
"to an updated file to be imported into Hyperion."
Do Until rstInputFile.EOF
With dbsHeadcount
strSQLHyperionMany = "SELECT [COUNTRY], [TYPE], " & _
"[BUSINESS_UNIT], [L_R_G], [REGION], [JOB_FUNCTION], [NUMFOREIGNKEY] " & _
"FROM [TBLHYPERIONMANY2] " & _
"WHERE [COUNTRY]='" & UCase(rstInputFile![COUNTRY]) & "' " & _
"AND [TYPE]='" & UCase(rstInputFile![Type]) & "' " & _
"AND [BUSINESS_UNIT]='" & UCase(rstInputFile![BUSINESS_UNIT]) & "' " & _
"AND [L_R_G]='" & UCase(rstInputFile![L_R_G]) & "' " & _
"AND [REGION]='" & UCase(rstInputFile![REGION]) & "' " & _
"AND [JOB_FUNCTION]='" & UCase(rstInputFile![JOB_FUNCTION]) & "'"
rstHyperionMany.Requery
Set qdfNew = dbsHeadcount.CreateQueryDef(strFileName, strSQLHyperionMany)
DoCmd.SetWarnings False
Set rstQueryDef = New ADODB.Recordset
strPassThroughQuery = "SELECT * FROM qryPassThroughQuery"
rstQueryDef.Open strPassThroughQuery, Cnxn, adOpenKeyset, adLockOptimistic
rstQueryDef.Requery
If rstQueryDef.RecordCount = 1 Then
rstInputFile![NUMINDEX] = rstQueryDef![NUMFOREIGNKEY]
Else
'MsgBox ("Record not found")
End If
prgProgressBar.Value = prgProgressBar.Value + 0.4
End With
dbsHeadcount.QueryDefs.Delete qdfNew.Name
rstQueryDef.Close
rstInputFile.MoveNext
Loop
End Sub
|
|
|
|
|
Can you not simplify your code with something like:
UPDATE [TBLINPUTFILE] SET [NUMINDEX] = [Hyp].[NUMFOREIGNKEY]
FROM [TBLHYPERIONMANY2] AS [Hyp]
WHERE [Hyp].[COUNTRY] = [TBLINPUTFILE].[COUNTRY]
AND [Hyp].[TYPE] = [TBLINPUTFILE].[TYPE]
AND [Hyp].[BUSINESS_UNIT] = [TBLINPUTFILE].[BUSINESS_UNIT]
AND [Hyp].[L_R_G] = [TBLINPUTFILE].[L_R_G]
AND [Hyp].[REGION] = [TBLINPUTFILE].[REGION]
AND [Hyp].[JOB_FUNCTION] = [TBLINPUTFILE].[JOB_FUNCTION] Regards
Andy
|
|
|
|
|
I have Vista Business (64bit) and I tried to install MS SQL SERVER 2005. My computer`s name is HFAST. During installation I have choosen 'Windows Authentication" and LocalSystem login. I`m running Administrator account.
Here is my problem: I have installed 2 database engines (one default and one named: SQL2005). Both are installed - I`m sure of it (they both appear when I try to uninstall SQL Serv 2005, and I can see them both on Visual Studio while choosing database to which to connect:
http://home.icslab.agh.edu.pl/~martinez/db1.jpg[^] ).
Nevertheless, I can`t connect to that engine with Management Studio. Here is my screen when I tried to connect to database engine: http://home.icslab.agh.edu.pl/~martinez/db2.jpg[^] .
Maybe security in Vista is the problem... I have no idea at all. Thank you very much for any help! Write if u need any more info
|
|
|
|
|
I had this problem connecting to SQL Express from my VISTA Home Premium system.
Try turning off the UAC - (In User Groups on the Control Panel). This fixed my connection problem immediately.
Hope this helps.
I support New Zealand...and anyone that is playing Australia - Kea Kaha
|
|
|
|
|
Can you show me how can i create(open,save,...)an ODB file and export it to another database ?
hungdl
|
|
|
|
|
What's your definition of an "ODB file"??
|
|
|
|
|
ODB(ORGANIZERS DATABASE),i mean
hungdl
|
|
|
|
|
Your single best source of information on this is going to be Organizers[^].
It's probably using either an Access database as a backend or an SQL server or MySql or something else. You'll have to contact them to find out what it's using and how, IF, you can use a different database engine or what it takes to export the data.
|
|
|
|
|
Hi
I am trying to convert an integer value to time is it possible in a query to convert?
For example a value 130210 stored as int should display as hh:mm:ss format.
Shahzad Aslam
Software Engineer
Softech Systems Limited
Cell: +92-321-4606036
Email: shehzadaslam@hotmail.com
|
|
|
|
|
I use:
CREATE FUNCTION [Lib].[IntToTime] (@Subject INT)
RETURNS DATETIME AS
BEGIN
DECLARE @result AS DATETIME
SET @result = '1970-01-01 00:00:00'
SET @result = DATEADD ( HH , @Subject/10000 , @result )
SET @Subject = @Subject - @Subject/10000*10000
SET @result = DATEADD ( mi , @Subject/100 , @result )
SET @Subject = @Subject - @Subject/100*100
SET @result = DATEADD ( ss , @Subject , @result )
RETURN ( @result )
END
Then you can CONVERT the DateTime to string as needed.
|
|
|
|