SQL Script Debugging - Just Being Curious
May 19, 2006
Dear Group
Something that I ever found quite difficult was finding a bug in a
script e.g. in a stp#ored procedure as often it would indicate the
error in a completely different line in which the error is actually
located. Take the following script
ALTER PROCEDURE [dbo].[fra_UpdateCompany]
@CompanyID int, @CompanyName varchar(50), @Status int, @TelNo
varchar(50), @FaxNo varchar(50), @Email varchar(50), @Web varchar(50),
@OfficeType int, @Comment varchar(512)
AS
DECLARE
@CommentOrg varchar(512)
IF (LEN(@CompanyName) < 1) BEGIN SET @CompanyName = NULL END
IF (LEN(@TelNo) < 1) BEGIN SET @TelNo = NULL END
IF (LEN(@FaxNo) < 1) BEGIN SET @FaxNo = NULL END
IF (LEN(@Email) < 1) BEGIN SET @Email = NULL END
IF (LEN(@Web) < 1) BEGIN SET @Web = NULL END
IF (LEN(@Comment) < 1) BEGIN SET @Comment = NULL END
SET @CommentOrg = (SELECT Comment from fra_company WHERE CompanyID =
@CompanyID)
SET @Comment = (@Comment + '' + @CommentOrg)
-- UPDATE COMPANY
UPDATE fra_company SET CompanyName = @CompanyName, Status = @Status,
TelNo = @TelNo, FaxNo = @FaxNo, Email = @Email, Web=@Web, OfficeType =
@OfficeType, Comment = LTRIM(@Comment) WHERE CompanyID = @CompanyID
It throws an error in Line 17 IF (LEN(@TelNo) < 1) BEGIN SET @TelNo =
NULL END when the error is actually in line 23: SET @CommentOrg =
(SELECT Comment from fra_company WHERE CompanyID = @CompanyID)
ErrorMsg:
Msg 137, Level 15, State 2, Procedure fra_UpdateCompany, Line 17
Must declare the scalar variable "@ContactID".
Why is that? I had hoped that it had improved from SQL 7.0 to 2005 but
it's still the same vague thing.
Thanks for sharing your expertise and wisdom on this,
Martin
View 2 Replies
ADVERTISEMENT
Jul 9, 2006
Hi,
I have found that when I'm debugging a custom component in BIDS that I've created in another instance of Visual Studio, every time I rebuild the component I have to shutdown and restart BIDS and then reattach to the BIDS process. Which is pretty time consuming... And if I find a small error in my custom component when debugging then I don't seem to be allowed to make any changes to the code unless I stop debugging and go through the process above.
Am I missing something here? Or do I really have to manually go through these steps every time I want to change code in the component I'm debugging?
Can I automate the process with MSBuild or NAnt? If so, is there an example of this anywhere?
Thanks in advance,
Lawrie.
View 1 Replies
View Related
Jun 12, 2002
Does anyone out there know if you can take a user like this domain1Username and without dropping it and recreating change it to domain2username. I am using Sql 7.
Thanks in advance
Troy
View 2 Replies
View Related
May 9, 2008
So, I kinda taught myself sql on the net in a couple of weeks... I've been practicing commands and what not with a database with a company I work with. Here's what I need some help with:
I'm creating a batch file that will connect to the sql server, and input a .sql in the batch file which launches the sql script to check to see if a store's data has come in or not, and if it hasn't, to launch the job to process that store. Now, after it launches the job, the only step for the job is to process what it can before it fails or completes, and most of the time it fails after 1-10 minutes. A big a variance. So my question is, how do I make it so that the script being called, waits for the job to finish before proceeding to the next command which checks a different store and launches another script?
If you want the script, I'll mod out some of the actual names for security purposes and post it for you guys. Any help is appreciated, and I've searched and hacked Google to get an answer, but nothing, so I decided to post this. Thanks!
View 1 Replies
View Related
Dec 17, 2007
Hi everybody
I want to know in the real world, what RDBMS is used for keeping people's accounts in official Banks( institution for saving and borrowing money) ? do they use SQL-Server , ORACLE or some thing else?
Thanks in advance.
Regards.
View 3 Replies
View Related
Sep 13, 2007
Whilst digging about in the systables I noticed 2 curious things:
When creating an application that returned all tables, columns and fields I had to use sys.systables, and when returning the information from this view, I received two identical columns 1. myColumn of type sysname and 2. myColumn of type varchar. The point being, what is this column for, and why is it there, as it was quite annoying to note it when returning the dataset in my app.
My other point is, while checking out what I could do with sysname, I noted the xml type has a capacity of -1, whereas all other data types have a capacity between 2-8000. Could someone clarify this for me, as it seems a single xml document could be inserted upto 2gb.
Regards.
View 1 Replies
View Related
Jul 23, 2005
How can I write a query to return non distinct results?
View 3 Replies
View Related
Sep 15, 2006
So I have a person who is adamant in tell me that SQL Server does not run on windows XP.
Now, I have already done all the research on this (i.e. sql server 2000 product page / requirements) and know the answer, but they insist on asking the question, so here it is .....
'Will SQL Server run on Windows XP'
A simple YES or NO will suffice; however, if you want to explain the answer (if it requires one ;) ), please feel free.
View 5 Replies
View Related
Apr 12, 2007
Can someone try and explain to me how a sql query can run fine and return data, yet when I try to run it in dtswizard, while the "preview" view shows the data, actually running it returns zero rows?
This is on SQL2005 express and since I can't get dtsrun or dtexec to work, I'm using auto-it to simulate my actually stepping through the process. Very kludgy, but "when all you've got is a hammer...."
View 6 Replies
View Related
May 3, 2008
Hi all
I have a Float Field in my table with following values:
1.63
7.42
35.71
0.58
every thing is ok BUT when i Select Data from this table in
QUERY ANALIZER environment with (Select * from mytable) , Query Analizer shows me the following values:
1.6299999999999999
7.4199999999999999
35.710000000000001
0.57999999999999996
Why? while i don't have this problem in Enterprise manager !!!
Thanks in advance.
Kind Regards.
View 2 Replies
View Related
Jul 23, 2005
Dear group,if someone could give me an idea what is going on in one of ourdatabases, this would really really be helpful.We have two tables with around 2 / 3 million rows. These tables have nokey and no ID. (This major design flaw will be overcome in some laterversion of the application-software working on this DB but right now ihave to live with this).Now for the funny bit1) I open one window in the Query-Analyzer and write some code likeBegin transaction INSERT INTO TABLE COMMIT2) in another window i write "SELECT COUNT(*) from TABLE"If I perform the insert then afterwards select count(*) the row-countis incremented by two whereas the Insert-Statement said "1 row(s)modified.DBCC gives no errors.DBCC gives amount of rows 2 million rowsSelect count(*) on the same table gives 3 million rowsExporting the data, truncating the table re-importing data gives noresult, right now the DTS-status is 203 and the machine is "thinking".Is there any possibility to check the "integrity" of the table?This problem is on the production machine, but right now i am workingon a copy so it was propagated with backup / restore-mechanism.Any hint would be very helpfulThanks and GreetingsUli
View 5 Replies
View Related
May 5, 2015
I found a code snippet that use the curious following sintax on the creation of View:
CREATE VIEW [dbo].[vw_EvenValues]
AS
SELECT [TestColumn]
FROM [dbo].[TestTable]
WHERE [TestColumn] % 2 = 1
[code]....
IF [TestColumn] on the Select is varchar, then error occurs and say:"Conversion failed when converting for the varchar value 'A001' to data type int"
View 7 Replies
View Related
Jul 20, 2005
Hi,I have been running some queries against a table in a my database andhave noted an odd (at least it seems odd to me) performance issue.The table has approximately 5 million rows and includes the followingcolumns:DocID (INTEGER, PRIMARY KEY, CLUSTERED)IsRecord (INTEGER, NONCLUSTERED)Title (VARCHAR(255), NONCLUSTERED)If I issue the following query:SELECT DocID, IsRecord FROM DocTable WHERE Title LIKE '%process%'it takes about 23 seconds to return the 481 hits.The execution plan shows a non-clustered index scan being performed onthe Title index (returning 481 rows) and a non-clustered index scan onthe IsRecord index (returning 4.9 million rows). These are then mergedin a hash match/inner join operation.The Title index scan has an estimated row size of 41 and an I/O costof 9.82 (cost is 27%). The IsRecord index scan has an estimated rowsize of 33 and an I/O cost of 6.32 (cost is 21%). The Hash Matchaccounts for a further 52% of the cose with the SELECT at the head ofthe plan listed as 0% cost.If I issue the following query:SELECT DocID, Title FROM DocTable WHERE Title LIKE '%process%'it takes about 12 seconds to return the 481 hits and consists solelyof a non-clustered index scan of the Title Index.Again the Title index scan has an estimated row size of 41 and an I/Ocost of 9.82 ans it's cost is listed as 78%. The SELECT at the head ofthe plan is attributed the other 22% of the cost.All this is fine, however when I issue the following query:SELECT DocID, Title, IsRecord FROM DocTable WHERE Title LIKE'%process%'it takes 1 minute 50 seconds to run the query. The execution plansshows that a clustered index scan is occurring and this accounts for96% of the cost. The estimated row size is 463 and the I/O cost is111.What on earth is going on here. I can understand the need to scan theTitle index because of the wildcards, but why on earth would the queryperform a scan of the clustered (primary key) index? And what is goingon with the row size and I/O cost?All the indexes and statistics are up to date, so I am at a completeloss to explain what is going on here. Can anyone explain why the 3rdquery is so much slower (and possibly suggest a way to improve theperformance)/ThanksPaul MateerMeridio LimtedI am at a complete loss to explain what is happening here,
View 3 Replies
View Related
Nov 17, 2004
Hi all,
Looking at BOL for temp tables help, I discover that a local temp table (I want to only have life within my stored proc) SHOULD be visible to all (child) stored procs called by the papa stored proc.
However, the following code works just peachy when I use a GLOBAL temp table (i.e., ##MyTempTbl) but fails when I use a local temp table (i.e., #MyTempTable). Through trial and error, and careful weeding efforts, I know that the error I get on the local version is coming from the xp_sendmail call. The error I get is: ODBC error 208 (42S02) Invalid object name '#MyTempTbl'.
Here is the code that works:SET NOCOUNT ON
CREATE TABLE ##MyTempTbl (SeqNo int identity, MyWords varchar(1000))
INSERT ##MyTempTbl values ('Put your long message here.')
INSERT ##MyTempTbl values ('Put your second long message here.')
INSERT ##MyTempTbl values ('put your really, really LONG message (yeah, every guy says his message is the longest...whatever!')
DECLARE @cmd varchar(256)
DECLARE @LargestEventSize int
DECLARE @Width int, @Msg varchar(128)
SELECT @LargestEventSize = Max(Len(MyWords))
FROM ##MyTempTbl
SET @cmd = 'SELECT Cast(MyWords AS varchar(' +
CONVERT(varchar(5), @LargestEventSize) +
')) FROM ##MyTempTbl order by SeqNo'
SET @Width = @LargestEventSize + 1
SET @Msg = 'Here is the junk you asked about' + CHAR(13) + '----------------------------'
EXECUTE Master.dbo.xp_sendmail
'YoMama@WhoKnows.com',
@query = @cmd,
@no_header= 'TRUE',
@width = @Width,
@dbuse = 'MyDB',
@subject='none of your darn business',
@message= @Msg
DROP TABLE ##MyTempTbl
The only thing I change to make it fail is the table name, change it from ##MyTempTbl to #MyTempTbl, and it dashes the email hopes of the stored procedure upon the jagged rocks of electronic despair.
Any insight anyone? Or is BOL just full of...well..."stuff"?
View 2 Replies
View Related
Dec 28, 2004
Hi.
I need to step into a SP on my SQL server. However, I get "Security hasn't been setup correctly on server RADU. SQL debugging terminated."
I read the docs, and I did exactly this (as per the help files):
---------------------------------------------------------------------------------------------------
To configure DCOM on the server for SQL debugging
You may need to download and install DCOM first. If so, go to http://www.microsoft.com/com/resources/downloads.asp for the latest version.
You must have administrator privileges on the machine where you are configuring DCOM.
From the Start menu, choose Run.
In the Open box, type dcomcnfg.exe.
Click OK.
The Component Services dialog box appears.
In the left pane of the Component Services dialog box, expand the Component Services node and find Computers.
Expand the Computers node and find the computer for which you want to configure DCOM.
Right-click the computer and choose Properties from the shortcut menu.
In the Properties dialog box, select the Default COM Security tab.
Under Access Permissions, click Edit Default.
The Access Permission dialog box appears.
If the group or user who needs access does not appear in the list of permissions, click Add.
The Users, Computers, or Groups dialog box appears.
In the Enter the object names to select box, type the name of the group or user who needs access.
Click OK.
The user is now added to the list.
If SYSTEM does not appear in the list of permissions, click Add.
The Users, Computers, or Groups dialog box appears.
In the Enter the object names to select box, type:
SYSTEM
Click OK.
SYSTEM is now added to the list.
In the Access Permission, select Allow for each user you added.
Click OK to close the Properties dialog box.
If you changed any settings in this procedure, restart SQL Server.
---------------------------------------------------------------------------------------------------
However, from inside VSnet IDE. I get the same message ("Security hasn't been setup correctly blah-blah-blah").
I have tried with users 'ASPNet' and 'VSDevelopers'. Which user should I choose ? Is there something else I should do ?
Sure, this is not the end of the world, I can still do the debug from within Query Analyzer, but still, it would be nice not to have to do this.
Thank you.
Alex
View 1 Replies
View Related
Aug 15, 2005
Hi,Is there a way to debug an SQL Server stored procedure? I call a number of sp's from my .net app and need a way to step through them.Thank you,
View 4 Replies
View Related
Dec 8, 1998
Does anyone use SQL debugging? I write pocedures in SQL server useing Developper studio, but i do not find any means to debug stored procedures.
Though i can place a break point to source code of sp_procedure, code is runned a whole.
Is this means only for C++?
Can anyone help me?
I have very large procedures and someteimes it is hard to find an error.
Ludek
View 1 Replies
View Related
Aug 13, 2007
select
if(acr_application.appStatus = 'AOO' then acr_application.appDt,
if(acr_application.appStatus = 'A01' then acr_application.recvdDt,
if(acr_application.appStatus = 'A02' then
(select A.payDt from acr_payment A, acr_reference_no B
where A.refNo = B.acrReferenceNoId and B.refType = 'ACF' and B.appNo =
acr_application.appNo),
if(acr_application.appStatus = ('A03', 'A08'),
(select C.updatedBy from acr_insp_sched C
where C.appNo = acr_application.appNo and C.seqNo =
(select max (D.seqNo) from acr_insp_sched D where D.appNo = C.appNo)),
if (acr_application.appStatus = ('A04', 'A05', 'A06', 'A15'),
(select E.updatedBy from acr_inspection E
where E.appNo = acr_application.appNo and E.seqNo =
(select max (F.seqNo) from acr_inspection F where F.appNo = E.appNo)),
if(acr_application.appStatus = 'A07',
(select G.payDt from acr_payment G, acr_reference_no H
where G.refNo = H.refId and H.refType = 'REI' and H.appNo =
acr_application.appNo),
if(acr_application.appStatus = ('A10', 'A11'), acr_application.approvedDt,
if(acr_application.appStatus = 'A13', acr_application.updatedBy,
if(acr_application.appStatus = 'A14',
(select H.payDt from acr_payment H, acr_reference_no J
where H.refNo = J.refId and J.refType = 'CSB' and J.appNo = acr_application.appNo), null)))))))))
from acr_application
View 4 Replies
View Related
Aug 21, 2007
In SQLServer 2000 I could easily debug a stored procedure from QA. But I dont know how to debug a sp in SQLServer 2005. I could find nothing to deal with it in SQL Server Management Studio. Can anybody tell me how to do it?
View 6 Replies
View Related
Dec 10, 2007
select
acr_application.appNo as 'applicationNo',
acr_application.facilityName as 'nameOf DrugTesting',
acr_application.adr as 'address',
acr_reference_no.refNo as 'referenceNo',
ref_charge.chargeDesc as 'charges/fee',
acr_reference_no.amount as 'amount',
ref_settings.earlyFileDiscnt as 'pdiscount',
((ref_settings.earlyFileDiscnt / 100) * acr_reference_no.amount) as 'discount',
case when acr_reference_no.earlyFileDiscntDt is not null then acr_reference_no.earlyFileDiscntDt
else
case when '2007-09-29' <= ref_facility.validToDt then date_sub(ref_facility.validToDt, interval (ref_settings.earlyFileDiscntValid + 1) day)
end
end as 'discountValidity',
ref_settings.lateFileDiscnt as 'psurcharge',
((ref_settings.lateFileDiscnt / 100) * acr_reference_no.amount) as 'surcharge',
case when acr_reference_no.lateFileSurchargeDt is not null then acr_reference_no.lateFileSurchargeDt
else
case when '2007-09-29' <= ref_facility.validToDt then ref_facility.validToDt, select a.validTodt from acr_application a where a.appNo = (select max(b.appNo) from acr_application b where b.appNo < acr_application.appNo)
end
end
end as 'surchargeValidity',
'0012 2222 20' as 'accountNumber',
concat('DOH-',acr_reference_no.refNo, '','-85619') as 'accountName',
concat(if(acr_application.ownerTitle is null or acr_application.ownerTitle='','', concat(acr_application.ownerTitle, '')),
acr_application.ownerFname, ' ',
if(acr_application.ownerMname is null or acr_application.ownerMname='','', concat(substr(acr_application.ownerMname,1,1),'.', ' ')),
acr_application.ownerLname, '', '',
if(acr_application.ownerSuffix is null or acr_application.ownerSuffix='','', concat(' ', acr_application.ownerSuffix))) as 'nameOfRepresentative'
case when acr_application.appType = 'INA' then acr_reference_no.amount
else
case when acr_application.appType = 'RNW' then
(if(acr_reference_no.earlyFileDiscnt is not null
and acr_reference_no.earlyFileDiscnt <='2007-09-29',
acr_reference_no.amount + (acr_reference_no.amount * (ref_settings.earlyFileDiscnt / 100))))
else
case when acr_reference_no.earlyFileDiscntDt is not null
and acr_reference.earlyFileDiscntDt > '2007-09-29'
and '2007-09-29' <= ref_facility.validToFt
then acr_reference_no.amount, acr_reference_no.amount + (acr_reference_no.amount * (ref_settings.earlyFileDiscnt / 100))
end
end
end as 'totalCashDeposit',
case when acr_application.appType = 'INA' then date_add(acr_applicationappDt, interval ref_settings.validityAfterAppDayy)
else
case when acr_application.appType = 'RNW' then acr_reference_no.earlyFileDiscntDt
else
case when acr_reference_no.earlyFileDiscntDt is not null and acr_reference_no.earlyFileDiscntDt > '2007-09-29' and '2007-09-29' <= ref_facility.validToDt then ref_facility.validToDt, date_add(ref_facility.validToDt, interval ref_settings.validityAfterAppDay)
end
end
end as 'bankValidity'
from acr_application
left join ref_facility on acr_application.appNo = ref_facility.appNo
left join ref_settings on ref_settings.service = acr_application.service and
ref_settings.ownType = acr_application.ownType and
ref_settings.facilityType = acr_application.facilityType and
ref_settings.institutChar = acr_application.institutChar
left join (acr_reference_no left join ref_charge on acr_reference_no.chargeId = ref_charge.chargeId and acr_reference_no.paid <> 'Y')
on acr_application.appNo = acr_reference_no.appNo
View 4 Replies
View Related
Jul 20, 2005
My colleagues and I have not been able to successfully set up SQL debugging on a SQL 2000 instance running on Windows 2000.Is there a checklist posted somewhere? We have verified that the SQL Server is not running with System Account Credentials. It runs as a Domain Administrator. We have also verified that everyone has permission to run sp_sdidebug. Does it matter that the Win2K machine is a Domain Controller? Any help would be appreciated.
View 1 Replies
View Related
Feb 14, 2008
Hi -
I am new to SSIS but not new to ETL. Is there a way in debugger to debug but not actually update the target table ? In other tools I€™ve used, there was an option setting to not allow update/inserts into the actual table, but would provide a visual dataset so you could see & test with. I haven€™t been able to find this feature in SSIS & was wondering if there is a way to do this.
Thanks -
View 3 Replies
View Related
Jan 11, 2008
Is there a way to step through sql when designing a query the way you can step through VB code in the IDE?
View 3 Replies
View Related
Oct 1, 2007
Hi, I am new here.
I tried to debug stored procedures in the Visual Studio and you know… it was a real shock. Like going in time 10 or 20 years back.
The stored procedures I deal with contain a lot of @tab and #tab, but it appears that I can not evaluate the values of these objects! The only type of object I can evaluate is a variable. But SQL is designed for the table data, right? So the most important type of data is not accessible!
How can I understand, what records have been affected by Update or inserted by Insert? Using prints or debug selects? Is it an era of FORTRAN or ALGOL???
To make it worse, to enter a debugger, I need to provide values of all parameters. It might be simple for the outermost procedure, but for inner stored procs, and where some parameters are some short-living identity values of some records, created in a transaction, it is very difficult to prepare all conditions to make a correct run.
So my question is, may be I had overlooked something? Is it a real debugger or just a joke from Microsoft? Sorry, but I am really angry after wasting a lot of time last week on it.
View 2 Replies
View Related
May 30, 2002
Does anyone know of any good debugging tools for transact sql? I know there is one by compuware called dbpartner but was looking for other options.
Thanks,
Eddie
View 1 Replies
View Related
Nov 5, 2001
I have a script that works in works in Query Analyzer, but when I try to put it in a DTS package, it fails. I have the database set properly in the data source. Can someone give me direction to figure out what is going on?
Brian
View 1 Replies
View Related
Nov 23, 1998
I'm looking for leads on any T-SQL / Trigger / Procedure editing and debugging tools for MSSQL 6.5 .
Any and all information would be appreciated.
Thanks in advance
Paul Gaynor
View 1 Replies
View Related
May 2, 2001
Hello,
I'm kind of new to SQL Server 2000, I've heard about debugging tools in Query Analyser
where can I find this tools?
Thanks
View 2 Replies
View Related
Jan 20, 2006
I was wondering if it is possible to pop up a dialog box from a SQL trigger.
This would be a great way to debug triggers as you could report variable values in the dialog box.
If not, does anybody have any suggestions as to the best way of reporting out variable values whilst a trigger is running?
View 2 Replies
View Related
Aug 1, 2006
From this msg im guessing that SQLE.DLL nee to be installed on my SQLServer box, is that correct? Where would i find this dll?
Server: Msg 508, Level 16, State 1, Procedure sp_sdidebug, Line 1
[Microsoft][ODBC SQL Server Driver][SQL Server]Unable to connect to debugger on APOLLO-ClintonSQL (Error = 0x800401f3). Ensure that client-side components, such as SQLLE.DLL, are installed and registered on PUR-CO-Clinton2. Debugging disabled for connection 59.
View 1 Replies
View Related
May 29, 2008
Ok, I am aware of the process to debug a stored proc for SQL 2005. I have never done anything in the Visual Studios 2005 so have had no reason to have it but now that I am pretty much forced into using SQL 2005, I have been deprived of the easy system of debugging stored procs from query analyzer. My question is...with the Visual Studios 2005 that was included with the SQL 2005 install, why does it not allow me to debug? I am aware of the whole Pro, Standard, etc of VS, but why not offer any way to debug? Am I missing something here? What options do I have to debug a stored proc other than running it over and over and over and over again to pinpoint an issue without getting VS2005 Pro or something?
View 4 Replies
View Related
Feb 3, 2004
After writing a Stored Procedure(which is giving correct reasult) how can I go for optimizing it?Is there any tool to debug a stored procedure?
View 1 Replies
View Related
Jun 5, 2008
I have been trying to debug a simple CLR function in VS2008 without any luck. I have searched Google and gone through several walk throughs without any luck. The function builds, deploys, and works from SQL fine but I cannot debug in VS. I created a new SQL login for a new user with SysAdmin privileges, and even set the permission level to "unsafe". Still, no debugging. The results in the output window of VS is "Canceled by user". I feel like this may be a permissions issue but I'm not sure. Can someone point me in the right direction to correct this? I use to debug CLR stored procs at another place of employment using VS all the time. Unfortunately, I wasn't involved with configuring it.
View 1 Replies
View Related