Cursor Declaration Blues

Dec 7, 1999

Hi!

While working for a client on a SQL Server 6.5 SP5a, I got the following error when running the code below in first SQL Enterprise Manager 6.5 and then SQL Query Analyzer 7.0:

IF @Departures = 1
DECLARE TableCursor CURSOR
FOR SELECT AcType,
BackPax = CASE BackPax
WHEN NULL THEN 0 ELSE BackPax END,
BestPax = CASE BestPax
WHEN NULL THEN 0 ELSE BestPax END,
DepTime,
FlightNumber,
ArrStn
FROM #TimeCall
ORDER BY DepTime, FlightNumber
ELSE
DECLARE TableCursor CURSOR
FOR SELECT AcType,
BackPax = CASE BackPax WHEN NULL THEN 0 ELSE BackPax END,
BestPax = CASE BestPax WHEN NULL THEN 0 ELSE BestPax END,
ArrTime,
FlightNumber,
DepStn
FROM #TimeCall
ORDER BY ArrTime, FlightNumber

And the error I get when the query is run for the first time after switching tool:

Server: Msg 202, Level 11, State 2, Procedure CreateFile, Line 178
Internal error -- Unable to open table at query execution time.
Server: Msg 202, Level 11, State 1, Procedure CreateFile, Line 188
Internal error -- Unable to open table at query execution time.

If I run the query again in one of the tools, it works. It also works if I use WITH RECOMPILE in the stored proc header.

If I use the code below, it also works, and without RECOMPILE:

DECLARE @SqlStr varchar( 255 )

IF @Departures = 1
SELECT @SqlStr = 'DECLARE TableCursor CURSOR ' +
'FOR SELECT AcType, ' +
'BackPax = CASE BackPax WHEN NULL THEN 0 ELSE BackPax END, ' +
'BestPax = CASE BestPax WHEN NULL THEN 0 ELSE BestPax END, ' +
'DepTime, FlightNumber, ArrStn ' +
'FROM #TimeCall ORDER BY DepTime, FlightNumber'
ELSE
SELECT @SqlStr = 'DECLARE TableCursor CURSOR ' +
'FOR SELECT AcType, ' +
'BackPax = CASE BackPax WHEN NULL THEN 0 ELSE BackPax END, ' +
'BestPax = CASE BestPax WHEN NULL THEN 0 ELSE BestPax END, ' +
'ArrTime, FlightNumber, DepStn ' +
'FROM #TimeCall ORDER BY ArrTime, FlightNumber'
EXECUTE( @SqlStr )

Trying to get around the problem with the following code did not do any good:

DECLARE TableCursor CURSOR FOR
SELECT AcType,
BackPax = CASE BackPax WHEN NULL THEN 0 ELSE BackPax END,
BestPax = CASE BestPax WHEN NULL THEN 0 ELSE BestPax END,
CurTime = CASE @Departures
WHEN 1 THEN DepTime
ELSE ArrTime END,
FlightNumber,
OtherStation = CASE @Departures
WHEN 1 THEN ArrStn
ELSE DepStn END
FROM #TimeCall
ORDER BY CurTime, FlightNumber

Server: Msg 202, Level 11, State 2, Procedure CreateFile, Line 176
Internal error -- Unable to open table at query execution time.

Anyone have some good ideas on why this happens?

Brgds

Jonas Hilmersson

View 1 Replies


ADVERTISEMENT

Using Variables In A Cursor Declaration

Aug 31, 2005

Hello All,I am trying to use a variable(@varStr ) in a cursor declaration. But I am unable to use it. something like:declare @intID as intset @intID  = 1DECLARE curDetailRecords CURSOR FOR (select fnameFrom Customers where id = @intID)Can we not use a variable in a cursor declaration.?ThanksImran

View 1 Replies View Related

Variable Assignment In Cursor Declaration

Jul 5, 2006

Hi,

here is the code segment below;
...
DECLARE find_dates CURSOR FOR
SELECT @SQL = 'select DISTINC(Dates) from ['+@name+'].dbo.['+@t_name+'] order by [Dates] ASC'
EXEC (@SQL)

but it gives error, variable assignment is not allowed in a cursor declaration. I need to use dynamic SQL , the only way to access all the dbs and their tables inside. Please help.

thanks

View 8 Replies View Related

Dynamic Cursor - Sorting In Declaration

Oct 6, 2006

Hello everybody!I have a small table "ABC" like this:id_position | value---------------------------1 | 112 | 223 | 33I try to use a dynamic cursor as below.When the statement "order by id_position" in declare part of the cursor_abcis omitted - cursor work as it should.But when the statement "order by id_position" is used, cursor behave asstatic one.What's the matter, does anybody know?Code:declare @id_position as int, @value as intDECLARE cursor_abc CURSORFORselect id_position, value from abcorder by id_positionset nocount onopen cursor_abcFETCH NEXT FROM cursor_abcINTO @id_position, @valueWHILE @@FETCH_STATUS = 0BEGINprint @id_positionprint @valueprint '----------------------------'update abc set value=666 --next reading should give value=666FETCH NEXT FROM cursor_abcINTO @id_position, @valueENDCLOSE cursor_abcDEALLOCATE cursor_abcGORegardsLucas

View 2 Replies View Related

Code Is Getting Compiled Even Columns Are Not Matching In Cursor Declaration

Jun 28, 2013

I have some stored procedure and there is a cursor inside it. I added some new columns to the table and those columns I included in the cursor declaration and fetch statement. In the cursor declaration I forgot to add comma (,) in between the new columns. So SQL Server it considers as a alias name for that column so syntactically it is correct. But logically in the cursor declaration having less number of columns than the columns in the fetch statement. So it should throw an error. But the procedure is getting compiled without raising any error. But if I execute the procedure that time it is throwing the error.

For example, below I have given the sample procedure. In this procedure, in the cursor declaration I removed the comma (,) between DOB and DOJ. If I compile this procedure it is getting compiled. But when execute that time only it is throwing the error. So I am interested in if any option is available to know the error in the compilation time itself.

ALTER PROCEDURE Test
AS
BEGIN
BEGIN TRY

DECLARE @empId INT,
@fname VARCHAR(50),
@dob DATE,
@doj DATE

[code]....

View 3 Replies View Related

Dataset Blues

Nov 2, 2007

i don't know if this is the right forum for this question but here goes.  I have created a gridview to display a list of records retrieved by a SQL query.  Everytime I run it, I get the following error:
Object must implement IConvertible.
 
I thought it might have to do with the data I'm passing in the session string from the previous page.  Here is that code:Protected Sub cmdSubmit_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles cmdSubmit.Click
Session.Add("Shift", shShift.SelectedItem)Session.Add("Type", shType.SelectedItem)
Session.Add("SelDate", OccDate.SelectedDate)
Response.Redirect("SelectIncRep.aspx")
 
Here is the code that is supposed to execute and display the data on page_init:
 
<asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="False" DataKeyNames="RID" DataSourceID="SqlDataSource1" Width="1215px" BorderStyle="Groove" BorderWidth="4px">
<Columns>
<asp:BoundField DataField="RID" HeaderText="Record ID:" InsertVisible="False" ReadOnly="True"
SortExpression="RID" />
<asp:BoundField DataField="Date" HeaderText="Date:" SortExpression="Date" />
<asp:BoundField DataField="Shift_ID" HeaderText="Shift:" SortExpression="Shift_ID" />
<asp:BoundField DataField="Xref_ID" HeaderText="Type Of Occurence:" SortExpression="Xref_ID" />
<asp:BoundField DataField="Notes" HeaderText="Notes:" SortExpression="Notes" />
</Columns>
</asp:GridView>
<asp:SqlDataSource ID="SqlDataSource1" runat="server" ConnectionString="<%$ ConnectionStrings:PerfDataConnectionString %>"
SelectCommand="SELECT [RID], [Notes], [Date], [Shift_ID], [Xref_ID] FROM [Safety_data] WHERE (([Shift_ID] = @Shift_ID) AND ([Xref_ID] = @Xref_ID) AND ([Date] = @Date))">
<SelectParameters>
<asp:SessionParameter Name="Shift_ID" SessionField="Shift_ID" Type="Int32" />
<asp:SessionParameter Name="Xref_ID" SessionField="Type" Type="Int32" />
<asp:SessionParameter Name="Date" SessionField="Date" Type="DateTime" />
</SelectParameters>
</asp:SqlDataSource>
 
What could be causing the issue?

View 5 Replies View Related

DTS Importing Blues -- Can Anyone Help?

Nov 18, 1999

I am importing via DTS a .csv file. I have 2 issues:

-One field from the source needs to be inserted into two existing fields.

-Two fields from the source, First_Name and Last_Name need to be
concatenated to a destination field, Full_Name.

I do not know VB but I do know SQL.

Can anyone help?

View 3 Replies View Related

Retirement Age Blues

Aug 8, 2006

Datediff won't give you an age.

For example:

SELECT (((DATEDIFF(DAY,BIRTHDATE,GETDATE())) / 30) / 12) as AGE

is CLOSE but not accurate. Is there another function I should consider in determining age?

Semper fi and Thanks!

Semper fi,
XERXES, USMC(Ret.)
------------------------------------------------------
The Marine Corps taught me everything but SQL!

View 7 Replies View Related

INSERTs Given Me The BLUES

Mar 22, 2006

cstring = cstring + "VALUES('%" + txtWatchID.Text + "%','%" + txtcenter + "%'" & _

cstring = "INSERT INTO tblNEW (watch_id, service_center_num, repair_envelope, store_number"

cstring = cstring + "date_purchase, transaction_num, cust_fname, cust_lname, product_code"

cstring = cstring + "value_watch, failure_date, service_date, failure_code, repair_code"

cstring = cstring + "service_request, store_number_senditem, register_number, street_address"

cstring = cstring + "city, state, zip_code, area_code, phone_num, product_desc, service_center"

cstring = cstring + " work_to_bdone, auth_num, labor_cost, parts_cost, tax_cost, total_cost"

cstring = cstring + "notes, client_number)"

cstring = cstring + "VALUES('%" + txtWatchID.Text + "%','%" + txtcenter + "%'" & _



this is the error is get, but i did the same thing on a select statement and it works fine...do i need to add something to the string or what i am kinda confused and help would be great.....

Operator '+' is not defined for types 'String' and 'System.Windows.Forms.TextBox'.

View 15 Replies View Related

RS2005 Setup Blues

Jul 10, 2007

I installed RS2005(SP2) with a SQL2000(sp4) db. Both are on seperate Windoes 2003 servers. I configured the reports manager to connect to a different web site on the same server instead of default web site. There were no installation prohlems. The RS server is up and running , all the virtual directories setup etc. When I try to access the reports directory via: http://dev2/Reports or browse the reports virtual directory from IIS, I get a 401 access denied error. The RS log reads:

<Header>
<Product>Microsoft SQL Server Reporting Services Version 9.00.3042.00</Product>
<Locale>en-US</Locale>
<TimeZone>Eastern Daylight Time</TimeZone>
<Path>D:ReportingServices2005MSSQL.1Reporting ServicesLogFilesReportServerWebApp__07_10_2007_11_29_21.log</Path>
<SystemName>NWISTCST99</SystemName>
<OSName>Microsoft Windows NT 5.2.3790 Service Pack 2</OSName>
<OSVersion>5.2.3790.131072</OSVersion>
</Header>
w3wp!library!1!7/10/2007-11:29:22:: i INFO: Initializing ReportBuilderTrustLevel to '0' as specified in Configuration file.
w3wp!library!1!7/10/2007-11:29:22:: i INFO: Initializing MaxActiveReqForOneUser to '20' requests(s) as specified in Configuration file.
w3wp!library!1!7/10/2007-11:29:22:: i INFO: Initializing MaxScheduleWait to default value of '1' second(s) because it was not specified in Configuration file.
w3wp!library!1!7/10/2007-11:29:22:: i INFO: Initializing DatabaseQueryTimeout to default value of '30' second(s) because it was not specified in Configuration file.
w3wp!library!1!7/10/2007-11:29:22:: i INFO: Initializing ProcessRecycleOptions to default value of '0' because it was not specified in Configuration file.
w3wp!library!1!7/10/2007-11:29:22:: i INFO: Initializing RunningRequestsScavengerCycle to default value of '30' second(s) because it was not specified in Configuration file.
w3wp!library!1!7/10/2007-11:29:22:: i INFO: Initializing RunningRequestsDbCycle to default value of '30' second(s) because it was not specified in Configuration file.
w3wp!library!1!7/10/2007-11:29:22:: i INFO: Initializing RunningRequestsAge to default value of '30' second(s) because it was not specified in Configuration file.
w3wp!library!1!7/10/2007-11:29:22:: i INFO: Initializing CleanupCycleMinutes to default value of '10' minute(s) because it was not specified in Configuration file.
w3wp!library!1!7/10/2007-11:29:22:: i INFO: Initializing DailyCleanupMinuteOfDay to default value of '120' minutes since midnight because it was not specified in Configuration file.
w3wp!library!1!7/10/2007-11:29:22:: i INFO: Initializing WatsonFlags to default value of '1064' because it was not specified in Configuration file.
w3wp!library!1!7/10/2007-11:29:22:: i INFO: Initializing WatsonDumpOnExceptions to default value of 'Microsoft.ReportingServices.Diagnostics.Utilities.InternalCatalogException,Microsoft.ReportingServices.Modeling.InternalModelingException' because it was not specified in Configuration file.
w3wp!library!1!7/10/2007-11:29:22:: i INFO: Initializing WatsonDumpExcludeIfContainsExceptions to default value of 'System.Data.SqlClient.SqlException,System.Threading.ThreadAbortException' because it was not specified in Configuration file.
w3wp!library!1!7/10/2007-11:29:22:: i INFO: Initializing SecureConnectionLevel to default value of '1' because it was not specified in Configuration file.
w3wp!library!1!7/10/2007-11:29:22:: i INFO: Initializing DisplayErrorLink to 'True' as specified in Configuration file.
w3wp!library!1!7/10/2007-11:29:22:: i INFO: Initializing WebServiceUseFileShareStorage to default value of 'False' because it was not specified in Configuration file.
w3wp!ui!5!7/10/2007-11:29:30:: e ERROR: The request failed with HTTP status 401: Unauthorized.
w3wp!ui!5!7/10/2007-11:29:31:: e ERROR: HTTP status code --> 500
-------Details--------
System.Net.WebException: The request failed with HTTP status 401: Unauthorized.

at Microsoft.SqlServer.ReportingServices2005.RSConnection.GetSecureMethods()

at Microsoft.ReportingServices.UI.Global.RSWebServiceWrapper.GetSecureMethods()

at Microsoft.SqlServer.ReportingServices2005.RSConnection.IsSecureMethod(String methodname)

at Microsoft.SqlServer.ReportingServices2005.RSConnection.ValidateConnection()

at Microsoft.ReportingServices.UI.ReportingPage.EnsureHttpsLevel(HttpsLevel level)

at Microsoft.ReportingServices.UI.ReportingPage.ReportingPage_Init(Object sender, EventArgs args)

at System.EventHandler.Invoke(Object sender, EventArgs e)

at System.Web.UI.Control.OnInit(EventArgs e)

at System.Web.UI.Page.OnInit(EventArgs e)

at System.Web.UI.Control.InitRecursive(Control namingContainer)

at System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint)
w3wp!ui!5!7/10/2007-11:29:32:: e ERROR: Exception in ShowErrorPage: System.Threading.ThreadAbortException: Thread was being aborted.
at System.Threading.Thread.AbortInternal()
at System.Threading.Thread.Abort(Object stateInfo)
at System.Web.HttpResponse.End()
at System.Web.HttpServerUtility.Transfer(String path, Boolean preserveForm)
at Microsoft.ReportingServices.UI.ReportingPage.ShowErrorPage(String errMsg) at at System.Threading.Thread.AbortInternal()
at System.Threading.Thread.Abort(Object stateInfo)
at System.Web.HttpResponse.End()
at System.Web.HttpServerUtility.Transfer(String path, Boolean preserveForm)
at Microsoft.ReportingServices.UI.ReportingPage.ShowErrorPage(String errMsg)




Please advise.

The RSweApplication.config in the ReportManager folder has the fully qualified URL to ReportServer<ReportServerUrl> and I have blanked out the <ReportServerVirtualDirectory>



Also the <UrlRoot> in rsreportserver.config in ReportServer folder points to the fully qualified URL to ReportServer.



What am I missing here ..?

View 6 Replies View Related

Linked Server Blues...msg 7319

Apr 24, 2001

Hi,

I have a linked server on two of my other servers. On one server, I can run linked queries just fine. On the other, I get the following error:

Server: Msg 7319, Level 16, State 1, Line 1
OLE DB provider 'SQLOLEDB' returned a 'NON-CLUSTERED and NOT INTEGRATED' index 'LOCATOR_ID' with incorrect bookmark ordinal 0.

I have SQL 7.0 SP2 on both of the linking servers, and the linked server is SQL 6.5. Both querying servers are also using MDAC 2.1

Any insight anyone could provide would be appreicated.

Joe

View 1 Replies View Related

Variable Declaration

Mar 29, 2004

hi,

i am new to sql server...

i have used @ symbol for declaring local variables in stored procedure....
The symbol @@ is there....where to use and what is the purpose of using that symbol...

could anyone tell...

thanks

View 1 Replies View Related

Declaration Of Record Variable

Oct 10, 2006

Can someone say how to declare a record like variable in MSSQL-2000 Like:
mr_rec record of variables a int, b char(20), c datetime? I could not find any examples on BOL. I want to use this in a stored procedure create script.

Thanks, Vinnie

View 1 Replies View Related

Declaration Expected Error

Oct 11, 2007

Hi,

I am trying to convert an active x script in a script task. Below is a snippet of code. The underlined AsOfDate has a blue squiggly line under it and if I hover over it, it says "Declaration Expected."


Public Class ScriptMain



Dim AsOfDate As String

AsOfDate = Dts.Variables("MyDate").Value
...

Can someone please tell me what I'm missing? I thought maybe I'm missing an import statement, but I have:

Imports Microsoft.SqlServer.Dts.Runtime

Imports Microsoft.SqlServer.Dts.Pipeline.Wrapper

I have used similar syntax in script components and it works fine.

Thanks

View 6 Replies View Related

Dynamic Variable Used In Decimal Declaration

Jun 18, 2007

I'm wondering if there's a way to pass a variable to assigning a decimal datatype;

declare @intPrecision int

set @intPrecision = 3

declare @decVariable decimal(38, @intPrecision)

I've basically been given the task by my mentor to create a script to round a decimal to a given number of decimal places.

ie; 1234.56789; 2 dp => 1234.57 and not 1234.57000

Any advice would be great.

View 1 Replies View Related

T-SQL (SS2K8) :: Variable Declaration In A Loop

Jul 2, 2015

I am reviewing some code we have inherited (riddled with multiple nested cursors) and in the process of re-writing some of the code. I came across this and it has me puzzled.

As I understand it, if you declare a variable and then try to re-declare a variable of the same name an error is generated. If I do this inside a While loop this does not seem to be the case. What ever is assigned is kept and just added to (in the case of a table variable)

I understand things are in scope for the batch currently running but I would expect an error to return (example 1 and 2)

--Table var declaration in loop
SET NOCOUNT ON
DECLARE @looper INT = 0
WHILE @looper <= 10
BEGIN
DECLARE @ATable TABLE ( somenumber INT )

[Code] ....

View 4 Replies View Related

Variable Declaration In A Stored Procedure Query

Feb 15, 2002

I have the following lines embedded in a stored procedure

---
----
----
select @querystr = "select @lkinpos = pos_lkin_pos from "+@database+" where pos_clnt_id = "+str(@clntid)+" and pos_isin ="+"'"+ @isinno+"'"

print @querystr
exec(@querystr)
---
---
---

When i execute the above stored procedure, it returns an error as follows:

Server: Msg 137, Level 15, State 1, Line 1
Must declare the variable '@lkinpos'.

When i see the print @querystr statement, it returns the query str as follows:

select @lkinpos = pos_lkin_pos from nsdldpm..pos_mstr where pos_clnt_id = 10000045 and pos_isin ='ine227a01011'

This when executed independently, gives me the required output.

Can anybody solve this for me?
Thanks in advance

View 1 Replies View Related

Analysis :: Dynamic Declaration Of Variable In MDX Query?

May 27, 2015

Is there a way to write such a query where we can declare the variable dynamically ? Currently I am using the query as shown below :

declare @pYear_Internal as NVarchar(100)
set @pYear_Internal = [D FISCALPERIOD].[FP CODE].[FP CODE]
WITH
MEMBER MEASURES.[REVENUE] AS [Measures].[TOTAL REVENUE]
SET LAST5YEARS AS STRTOMEMBER(@pYear_Internal).Lag(4) : STRTOMEMBER(@pYear_Internal)

[code]....

While executing the above query, getting the error - Query (1, 9) Parser: The syntax for '@pYear_Internal' is incorrect.  It looks like it doesn't recognize DECLARE keyword as it does with SQL queries.  I just want a query that runs directly against the server. 

View 3 Replies View Related

Need Help Understanding A Stored Procedure Variable Declaration

Oct 25, 2007

I've been curious why some variables don't need to be declared with a value type in a stored procedure. Please see the example below in the bolded area. The stored procedure works fine - nothing is wrong with it, but I just wanted an explanation on why and when is a value type not needed for a variable.

CREATE PROCEDURE [DBO].[EmailRpt]
(
@TagDest char(2) = NULL,
@DateWanted smalldatetime = NULL,
@CustName varchar(64) = NULL,
@AcctID AcctId = NULL,
@ContactPhn phone = NULL,
@CustAddr address = NULL,
@City city,
@CrossSt varchar(50) ,
@Access varchar(50) = NULL,
@Activity tinyint,
)
AS
DECLARE @String as varchar(2000),
@Header as varchar(200),
@MailBox as varchar(50),
@ActivityName as Name,
@Return as int,
@UserName as Name

View 5 Replies View Related

Xslt Filters On Xml Output. Cdata-section-elements And Omit-xml-declaration Problems.

Sep 14, 2006

Hi All,



I'm using some xslt documents to transform the xml output of my Reports
but have come across two curiosities where the xslt filter seems to
behave unusually.



Firstly, I need the final saved file to have an xml declaration, which
I believe it should do by default. Even if I put
omit-xml-declaration="no" in the xsl:output tag I don't get an xml
declaration. At present we have a custom job that writes these
declarations back into the xml after SRS has saved it.



Secondly and more importantly, I need to have some of my output tags
wrapped in CDATA sections. I've tried using the cdata-section-elements
attribute, again with no luck.

my XSLT looks something like this (simplified for space)



<?xml version="1.0" encoding="utf-8"?>

<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">

<xsl:output method="xml" encoding="utf-8" media-type="text/xml" omit-xml-declaration="no" cdata-section-elements="description"/>

<xsl:template match="/">

<xsl:for-each select="Report/table1/Detail_Collection/Detail">

<item>

<description>


<xsl:value-of select="@Description"/>

</description>

</item>

</xsl:for-each>

</xsl:template>

</xsl:stylesheet>



The output is something like:



<item>

<description>My first description text...</description>

</item>


<item>


<description>My seconddescription text...</description>


</item>



What I want is:

<?xml version="1.0" encoding="utf-8"?>

<item>


<description><![CDATA[My first description text...]]></description>


</item>



<item>



<description><![CDATA[My secondfirst description text...]]></description>



</item>



All help gratefully appreciated.



Thanks - Andrew.

View 5 Replies View Related

SQL Server 2000 Requires Explicit Declaration Of Data Types In Client App After Installing A Certain HotFix

Jun 15, 2004

I think I may have figured out the solution to my recent conundrum with SQL Server 2000 that had me stressed and depressed over the last couple of days. In a nutshell, after a HotFix was installed on a SQL2K database server I have space on, I was unable to perform INSERT or UPDATE queries on database table of type TEXT, when trying to either create or modify records with more than 4,000 characters of data. While it was frustrating as heck, it seemed too rigid to be random, so I did some snooping.

The HotFix was intended to solve a known problem of not being able to run UPDATEs against TEXT fields, but in so doing, caused another headache entirely: http://support.microsoft.com/?kbid=839523

Apparently this is a semi-known problem, in that a certain HotFix forces SQL Server 2000 to be a lot more stringent in requiring explicit declaration of data types and data lengths for parameters in stored procedure. In my client code, I was initially using the overloaded constructor of the SqlParameter object that took as arguments only the parameter name and a value, without specifying a value from the SQLDBType enumeration or length of the parameter (which in my case, needs to be TEXT and 16 (or 2147483647), respectively):

System.Data.SqlDataAdapter.InsertCommand.Parameters.Add(new SqlParameter("@parameterName",parameterValue);

It appears that after the HotFix is installed, if the client doesn’t syntactically set the type and length of data for a parameter, SQL Server and/or .NET will default to a type of NVARCHAR, which has the 4,000-character limit. This all makes sense. I’m going to now need to modify the code to straight out declare what’s going in the SPROC:

System.Data.SqlDataAdapter.InsertCommand.Parameters.Add(new SqlParameter("@parameterName",SqlDbType.Text);
System.Data.SqlDataAdapter.InsertCommand.Parameters["@parameterName"].Value = parameterValue;

It’s a minor change, and it sucks that I have to make it after the code had worked flawlessly over several thousands executions over several months, but c’est la vie! Better thay than have to rebuild my DB from scratch or switch to a new server. Changing the client code evidently is the only known fix at this time: http://support.microsoft.com/default.aspx?scid=kb%3ben-us%3b827366

View 1 Replies View Related

Transact SQL :: STATIC Defines A Cursor That Makes Temporary Copy Of Data To Be Used By Cursor

Aug 12, 2015

In MSDN file I read about static cursor

STATIC
Defines a cursor that makes a temporary copy of the data to be used by the cursor. All requests to the cursor are answered from this temporary table in
tempdb; therefore, modifications made to base tables are not reflected in the data returned by fetches made to this cursor, and this cursor does not allow modifications

It say's that modifications is not allowed in the static cursor. I have a  questions regarding that

Static Cursor
declare ll cursor global static
            for select  name, salary from ag
  open ll
             fetch from ll
 
              while @@FETCH_STATUS=0
               fetch from ll
                update ag set salary=200 where 1=1
 
   close ll
deallocate ll

In "AG" table, "SALARY" was 100 for all the entries. When I run the Cursor, it showed the salary value as "100" correctly.After the cursor was closed, I run the query select * from AG.But the result had updated to salary 200 as given in the cursor. file says  modifications is not allowed in the static cursor.But I am able to update the data using static cursor.

View 3 Replies View Related

Dynamic Cursor Versus Forward Only Cursor Gives Poor Performance

Jul 20, 2005

Hello,I have a test database with table A containing 10,000 rows and a tableB containing 100,000 rows. Rows in B are "children" of rows in A -each row in A has 10 related rows in B (ie. B has a foreign key to A).Using ODBC I am executing the following loop 10,000 times, expressedbelow in pseudo-code:"select * from A order by a_pk option (fast 1)""fetch from A result set""select * from B where where fk_to_a = 'xxx' order by b_pk option(fast 1)""fetch from B result set" repeated 10 timesIn the above psueod-code 'xxx' is the primary key of the current Arow. NOTE: it is not a mistake that we are repeatedly doing the Aquery and retrieving only the first row.When the queries use fast-forward-only cursors this takes about 2.5minutes. When the queries use dynamic cursors this takes about 1 hour.Does anyone know why the dynamic cursor is killing performance?Because of the SQL Server ODBC driver it is not possible to havenested/multiple fast-forward-only cursors, hence I need to exploreother alternatives.I can only assume that a different query plan is getting constructedfor the dynamic cursor case versus the fast forward only cursor, but Ihave no way of finding out what that query plan is.All help appreciated.Kevin

View 1 Replies View Related

Could Not Complete Cursor Operation Because The Set Options Have Changed Since The Cursor Was Declared.

Sep 20, 2007

I'm trying to implement a sp_MSforeachsp howvever when I call sp_MSforeach_worker
I get the following error can you please explain this problem to me so I can over come the issue.


Msg 16958, Level 16, State 3, Procedure sp_MSforeach_worker, Line 31

Could not complete cursor operation because the set options have changed since the cursor was declared.

Msg 16958, Level 16, State 3, Procedure sp_MSforeach_worker, Line 32

Could not complete cursor operation because the set options have changed since the cursor was declared.

Msg 16917, Level 16, State 1, Procedure sp_MSforeach_worker, Line 153

Cursor is not open.

here is the stored procedure:


Alter PROCEDURE [dbo].[sp_MSforeachsp]

@command1 nvarchar(2000)

, @replacechar nchar(1) = N'?'

, @command2 nvarchar(2000) = null

, @command3 nvarchar(2000) = null

, @whereand nvarchar(2000) = null

, @precommand nvarchar(2000) = null

, @postcommand nvarchar(2000) = null

AS

/* This procedure belongs in the "master" database so it is acessible to all databases */

/* This proc returns one or more rows for each stored procedure */

/* @precommand and @postcommand may be used to force a single result set via a temp table. */

declare @retval int

if (@precommand is not null) EXECUTE(@precommand)

/* Create the select */

EXECUTE(N'declare hCForEachTable cursor global for

SELECT QUOTENAME(SPECIFIC_SCHEMA)+''.''+QUOTENAME(ROUTINE_NAME)

FROM INFORMATION_SCHEMA.ROUTINES

WHERE ROUTINE_TYPE = ''PROCEDURE''

AND OBJECTPROPERTY(OBJECT_ID(QUOTENAME(SPECIFIC_SCHEMA)+''.''+QUOTENAME(ROUTINE_NAME)), ''IsMSShipped'') = 0 '

+ @whereand)

select @retval = @@error

if (@retval = 0)

EXECUTE @retval = [dbo].sp_MSforeach_worker @command1, @replacechar, @command2, @command3, 0

if (@retval = 0 and @postcommand is not null)

EXECUTE(@postcommand)

RETURN @retval



GO


example useage:


EXEC sp_MSforeachsp @command1="PRINT '?' GRANT EXECUTE ON ? TO [superuser]"

GO

View 7 Replies View Related

T-SQL (SS2K8) :: Procedure Parameter Length Declaration Less Than Column Length?

Jun 30, 2014

is there any way or a tool to identify if in procedure the Parameter length was declarated less than table Column length ..

I have a table

CREATE TABLE TEST001 (KeyName Varchar(100) ) a procedure
CREATE PROCEDURE SpFindNames ( @KeyName VARCHAR(40) )
AS
BEGIN
SELECT KeyName FROM TEST001
WHERE KeyName = @KeyName
END
KeyName = @KeyName

Here table Column with 100 char length "KeyName" was compared with SP parameter "@KeyName" with length 40 char ..

IS there any way to find out all such usage on the ALL Procedures in the Database ?

View 2 Replies View Related

Join Cursor With Table Outside Of Cursor

Sep 25, 2007

part 1

Declare @SQLCMD varchar(5000)
DECLARE @DBNAME VARCHAR (5000)

DECLARE DBCur CURSOR FOR
SELECT U_OB_DB FROM [@OB_TB04_COMPDATA]

OPEN DBCur
FETCH NEXT FROM DBCur INTO @DBNAME


WHILE @@FETCH_STATUS = 0
BEGIN

SELECT @SQLCMD = 'SELECT T0.CARDCODE, T0.U_OB_TID AS TRANSID, T0.DOCNUM AS INV_NO, ' +
+ 'T0.DOCDATE AS INV_DATE, T0.DOCTOTAL AS INV_AMT, T0.U_OB_DONO AS DONO ' +
+ 'FROM ' + @DBNAME + '.dbo.OINV T0 WHERE T0.U_OB_TID IS NOT NULL'
EXEC(@SQLCMD)
PRINT @SQLCMD
FETCH NEXT FROM DBCur INTO @DBNAME

END

CLOSE DBCur
DEALLOCATE DBCur


Part 2

SELECT
T4.U_OB_PCOMP AS PARENTCOMP, T0.CARDCODE, T0.CARDNAME, ISNULL(T0.U_OB_TID,'') AS TRANSID, T0.DOCNUM AS SONO, T0.DOCDATE AS SODATE,
SUM(T1.QUANTITY) AS SOQTY, T0.DOCTOTAL - T0.TOTALEXPNS AS SO_AMT, T3.DOCNUM AS DONO, T3.DOCDATE AS DO_DATE,
SUM(T2.QUANTITY) AS DOQTY, T3.DOCTOTAL - T3.TOTALEXPNS AS DO_AMT
INTO #MAIN
FROM
ORDR T0
JOIN RDR1 T1 ON T0.DOCENTRY = T1.DOCENTRY
LEFT JOIN DLN1 T2 ON T1.DOCENTRY = T2.BASEENTRY AND T1.LINENUM = T2.BASELINE AND T2.BASETYPE = T0.OBJTYPE
LEFT JOIN ODLN T3 ON T2.DOCENTRY = T3.DOCENTRY
LEFT JOIN OCRD T4 ON T0.CARDCODE = T4.CARDCODE
WHERE ISNULL(T0.U_OB_TID,0) <> 0
GROUP BY T4.U_OB_PCOMP, T0.CARDCODE,T0.CARDNAME, T0.U_OB_TID, T0.DOCNUM, T0.DOCDATE, T3.DOCNUM, T3.DOCDATE, T0.DOCTOTAL, T3.DOCTOTAL, T3.TOTALEXPNS, T0.TOTALEXPNS


my question is,
how to join the part 1 n part 2?
is there posibility?

View 1 Replies View Related

Cursor Inside A Cursor

Oct 5, 2004

I'm new to cursors, and I'm not sure what's wrong with this code, it run for ever and when I stop it I get cursor open errors




declare Q cursor for
select systudentid from satrans


declare @id int

open Q
fetch next from Q into @id
while @@fetch_status = 0
begin

declare c cursor for

Select
b.ssn,
SaTrans.SyStudentID,
satrans.date,
satrans.type,
SaTrans.SyCampusID,
Amount = Case SaTrans.Type
When 'P' Then SaTrans.Amount * -1
When 'C' Then SaTrans.Amount * -1
Else SaTrans.Amount END

From SaTrans , systudent b where satrans.systudentid = b.systudentid

and satrans.systudentid = @id




declare @arbalance money, @type varchar, @ssn varchar, @amount money, @systudentid int, @transdate datetime, @sycampusid int, @before money

set @arbalance = 0
open c
fetch next from c into @ssn, @systudentid, @transdate, @type, @sycampusid, @amount

while @@fetch_status = 0
begin

set @arbalance = @arbalance + @amount
set @before = @arbalance -@amount

insert c2000_utility1..tempbalhistory1
select @systudentid systudentid, @sycampusid sycampusid, @transdate transdate, @amount amount, @type type, @arbalance Arbalance, @before BeforeBalance
where( convert (int,@amount) <= -50
or @amount * -1 > @before * .02)
and @type = 'P'




fetch next from c into @ssn, @systudentid, @transdate, @type, @sycampusid, @amount
end
close c
deallocate c
fetch next from Q into @id

end
close Q
deallocate Q


select * from c2000_utility1..tempbalhistory1
truncate table c2000_utility1..tempbalhistory1

View 1 Replies View Related

Client Side Cursor Vs Sever Side Cursor?

Jul 20, 2005

I having a difficult time here trying to figure out what to do here.I need a way to scroll through a recordset and display the resultswith both forward and backward movement on a web page(PHP usingADO/COM)..I know that if I use a client side cursor all the records get shovedto the client everytime that stored procedure is executed..if thisdatabase grows big wont that be an issue?..I know that I can set up a server side cursor that will only send therecord I need to the front end but..Ive been reading around and a lot of people have been saying never touse a server side cursor because of peformance issues.So i guess im weighing network performance needs with the client sidecursor vs server performance with the server side cursor..I am reallyconfused..which one should I use?-Jim

View 1 Replies View Related

Need Help With A Cursor

Jul 25, 2006

I hope this is the appropriate forum for this question, if not then I apologize.
I've got a SQL Server 2000 stored procedure that returns data to be used in a crystal report in Visual Studio 2005.  Most of the stored procedure works well, but there is a point where I need to calculate an average number of days been a group of date pairs. 
I'm not familiar with cursors, but I think that I will need to use one to achieve the result I am looking for so I came up with the code below which is a snippet from my stored procedure.  In this part of the code, the sp looks at the temporary table #lmreport (which holds all of the data that is returned at the end to crystal) and for every row in the table where the terrid is 'T' (the territory is domestic), it selects all of those territories from the territory table and loops through them to determine the date averages (by calling a nested stored procedure, also included below) for each territory and then updates #lmreport with that data.
When I try to run the stored procedure, I get "The column prefix '#lmreport' does not match with a table name or alias name used in the query." on the line indicated. 
Does anyone have any idea what might be wrong or if this will even work the way I need it to?
Thank you in advance.
 

View 1 Replies View Related

Cursor For

Sep 27, 2007

Hi,
Declare wh_ctry_id CURSOR FOR 
 
Is "cursor for" is a function or datatype or what is this?
Regards
Abdul

View 3 Replies View Related

Use Of Cursor

Oct 21, 2007

 
 I need some help with the concept of a Cursor, as I see it being used in a stored procedure I need to maintain.
Here is some code from the stored proc. Can someone tell me what is going on here. I haveleft out some of the sql, but have isolated the Cursor stuff.
Open MarketCursor  -- How is MarketCursor loaded with data ?
FETCH NEXT
FROM MarketCursorINTO ItemID, @Item, @Reguest
WHILE @@FETCH_STATUS = 0BEGIN
 
DEALLOCATE MarketCursor
 

View 1 Replies View Related

Is This Possible Without A Cursor?

Dec 5, 2007

 I have something like
 update table
set field = ...
where field = ...
 and for each entry that was effected by this query I want to insert an entry into another table.
I have always done this with cursors is there a more effecient way?  For some reason cursors run a lot slower on my sql2005 server than the sql2000 server...

View 2 Replies View Related

How Cursor Used In Asp.net

Mar 17, 2008

hii have creted cursor but i want to use in my asp.net programming when some insert or delete command is work that time i want to excute my cursor how can i do that using asp.net with c#  waiting for replaythanks 

View 4 Replies View Related







Copyrights 2005-15 www.BigResource.com, All rights reserved