Using DB Cursor In Conjunction With Dynamically Created Sql

Oct 29, 2004

OK...





I have an sql statement that i have manually built as a string. normally i would just return a recordset with it using











Set @sqlBuild = 'SELECT * FROM ' + @Table + ' WHERE value = ' + @value





EXEC (sqlBuild)











something like that works fine...





however, i would like to know if i can instead of just executing the SQL statement use that dynamically built statement with a cursor somehow.





basically what i'm trying to do is loop through that result set with a cursor instead of just simply executing it.





Any suggestions?

View 1 Replies


ADVERTISEMENT

Dynamically Created Dataset

Jan 26, 2007

I am building a mailing list report.

I have the report all built to display name, address, etc and this works well if i build the dataset in RS.

Problem:
I want to use this same report to build mailing list for any group of people the user selects while using a c# application.

Question:
Is there anyway to build a dataset in an application then send it to RS?

thanks
lucas

View 5 Replies View Related

Dynamically Created Stored Procs???

Mar 8, 2004

Okay. Scenario:

We as a company have several companies that request custom reports from us. However, the custom reports that they select will generally always have the same fields (and formulas) once they make up their minds on what works for them.

From what I know, Stored Procs are usually faster at running things unless the parameters are changing too drastically that they get passed.

This being the case, it would seem like a good case for creating a stored proc per report. This would alleviate the possability that the server chooses an execution plan that works great some of the time but the rest of the time run lousy.

So these thoughts being laid out, is there a good,nice,easy, convenient way to generate/alter a stored proc, either by another stored/extended proc, or by dynamic sql going to the server?

Or if not, is there some round-about yet effective way of doing this?


Thank you in advance for any help.
-ZanderB

View 8 Replies View Related

Cursor Isn't Being Created.

Aug 15, 2007

ElementTypeDep_Cursor seems is not being created in this stored procedure:




Code Snippet
ALTER procedure spCopyTemplateElementTypesToIssues
@TemplateRecno integer,
@ProjRecNo integer,
@IssueRecNo integer
as
declare @ElementTypeRecno integer
declare @ElementTypeDepRecno integer
declare @ProjTypeRecno integer
declare @PreElementRecNo integer
declare @PostElementRecno integer
declare @Count integer
DECLARE element_Cursor CURSOR FOR
SELECT ElementTypeRecNo
FROM dbo.tblTemplateElementType
where TemplateRecno = @TemplateRecNo
OPEN element_cursor
FETCH NEXT FROM Element_Cursor into @ElementTypeRecno
--delete from tblElementCPO
WHILE @@FETCH_STATUS = 0
BEGIN
select @count = count (*)
from tblElementCPO
where ProjRecno = @ProjRecNo
and IssueRecno = @IssueRecno
and TemplateRecno = @TemplateRecno
and ElementTypeRecno = @ElementTypeRecNo
if @Count = 0
begin
insert into tblElementCPO(Ignore, ElementTypeRecno, IssueRecno,
ProjRecno, MaxAttemptNum, IsMileStone, ComponentOnly, Phase,
TaskHoursEst, TemplateRecNo, ChangeDate, ChangePerson)
values (0, @ElementTypeRecno, @IssueRecno,
@ProjRecno, 5,0,6,99,
99,@TemplateRecno, getdate(), current_user)
end
FETCH NEXT FROM element_Cursor into @ElementTypeRecno
END
CLOSE element_Cursor
DEALLOCATE element_Cursor
select @Count = count (*)
FROM dbo.tblElementTypeDep
where TemplateRecno = @TemplateRecNo
if @Count > 0 then
begin
DECLARE ElementTypeDep_Cursor CURSOR FOR
SELECT ElementTypeDepRecNo, PreElementTypeRecNo, PostElementTypeRecno
FROM dbo.tblElementTypeDep
where TemplateRecno = @TemplateRecNo
OPEN ElementTypeDep_cursor
FETCH NEXT FROM ElementTypeDep_Cursor
into @ElementTypeDepRecno, @PreElementRecNo, @PostElementRecno
WHILE @@FETCH_STATUS = 0
BEGIN
select @Count = count (*)
from tblElementDepCPO
where ElementTypeDepRecno = @ElementTypeDepRecno
and PreElementRecNo = @PreElementRecNo
and PostElementRecno = @PostElementRecno
if @Count = 0
begin
insert tblElementDepCPO (ElementTypeDepRecno, PreElementRecNo,
PostElementRecno, ChangeDate, ChangePerson)
values (@ElementTypeDepRecno, @PreElementRecNo,
@PostElementRecno, getdate(), current_user)
end
FETCH NEXT FROM ElementTypeDep_Cursor
into @ElementTypeDepRecno, @PreElementRecNo, @PostElementRecno
END
CLOSE elementTypeDep_Cursor
DEALLOCATE elementTypeDep_Cursor
end


called by
Code Snippet
Dim cnQI02414 As New SqlConnection(My.Settings.csQI02414Dev)
Dim cmd As New SqlCommand
Dim reader As SqlDataReader
cmd.CommandText = "spCopyTemplateElementTypesToIssues"
cmd.CommandType = CommandType.StoredProcedure
Dim spmTemplateRecNo As SqlParameter = _
cmd.Parameters.Add("@TemplateRecNo", SqlDbType.Int)
spmTemplateRecNo.Value = _
Me.cbTemplate.SelectedValue
Dim spmProjRecNo As SqlParameter = _
cmd.Parameters.Add("@ProjRecNo", SqlDbType.Int)

spmProjRecNo.Value = _
Me.cbProject.SelectedValue

Dim spmIssueRecNo As SqlParameter = _
cmd.Parameters.Add("@IssueRecNo", SqlDbType.Int)

spmIssueRecNo.Value = _
Me.cbIssue.SelectedValue

cmd.Connection = cnQI02414
cnQI02414.Open()
reader = cmd.ExecuteReader()
' Data is accessible through the DataReader object here.
cnQI02414.Close()





What should I be looking for?



View 1 Replies View Related

Dynamically Listing Created Temp Tables

Jan 21, 2002

Hi,

I want to create a nested SP which will dump out the results of All Temp Tables that are currently created in the session. The purpose of this is for createing a generic debugging SP which will write the contents of all temp tables to a debug table (when a certain flag is set).

I need to know how to:

- Get a list of all temp tables created
- Get a list from each temp table of the columns created.

Hope someone can help!

Cheers,

Andrew

View 1 Replies View Related

Using A Dynamically Created Parameter In Another Dataset Query

Jul 27, 2007



It's been a while since I used Reporting Services so I'm sure this is really straight forward. Basically I have the following report parameters:

reportMonth - Just a non-queried list of months for the user to select
reportYear - Generated using the following query from dataset "Years":

declare @curYear int
set @curYear = 2000
declare @yearTable table (repYear int not null)
while @curYear <= year(getdate())
begin
insert into @yearTable(repYear) values (@curYear)
set @curYear = @curYear + 1
end
select * from @yearTable

This generated a list like:

2000
2001
2002
etc.

I then have a 2nd dataset "Main" which I'd like to use both the reportMonth and reportYear parameters in once they've been generated. How do I go about setting this up and referencing the parameters? I've tried a few things but nothing seems to be working.

Thanks

View 10 Replies View Related

Filter Dynamically Created Data Tables Using Sql Query

May 24, 2008

Hi friendsI have little problem here.I am creating data tables dynamically.I want to filter it using sql query.Suppose,
I have four data tables with the same structure but records may be
different.There are two fields ServiceMethod and Rates.Now I want to filter all tables and want to get match records with the ServiceMethod.Suppose,four records in First table,three records in other three tables,and only two records(Service method) are same in all tables.I
want to that two records by filtering all tables and sum of rates and
want to add matched records in new table and bind dropdownlist.Can any guide me how to filter more than one tables using sql query if data tables are created dynamically?Thanks in advance. 

View 2 Replies View Related

Stored Procedures - Using Return Value From Dynamically Created SQL Statement

Jul 29, 2007

Hello,

This is my foray into Stored procedures, so I'm hoping this is a fairly basic question.

I'm writing a stored procedure, in which I dynamically create an SQL statement.
At the end of this, the SQL statement reads like:



Code SnippetSELECT COUNT(*) FROM StockLedger WHERE StockCode = 'STOCK1' AND IsOpen = 1 AND SizeCode = 'L' AND ColourCode = 'RED' AND LocationCode IS NULL AND RemainingQty > 0



Now this statement works a charm, and returns a single value. I want to assign this count to a variable, and use it further on in the stored procedure. This is where the problems start - I cant seem to do it.

If I hard code a statement, like



Code SnippetSELECT @LineCount = COUNT(*) FROM StockLedger
that works fine (although it brings back a count of all the lines).

But if I modify the dynamically created SQL Statement from earlier on to:



Code SnippetSELECT @LineCount = COUNT(*) FROM StockLedger WHERE StockCode = 'STOCK1' AND IsOpen = 1 AND SizeCode = 'L' AND ColourCode = 'RED' AND LocationCode IS NULL AND RemainingQty > 0
it doesnt work - it complains: Must declare the scalar variable "@LineCount".

Just to clarify, when I say "dynamically created an SQL statement, I mean that by a bunch of conditional statements I populate a varchar variable with the statement, and then eventually run it exec(@SQLStatementString)

So, my question would be, how do I do this? How do I make a dynamically generated SQL statement return a value to a variable?


View 3 Replies View Related

Administrative Rights For Local Machine To Deploy Dynamically Created Report From Web App To Report Server

Feb 5, 2007

The current way I have my asp.net 2.0 web app running reports is, based on an
interface the user selects the criteria for a report. The .RDL file is created
dynamically based on the user's selections.
I then need to SOAP the dynamically created report to the report server and
then the report runs fine.
BUT it requires Adminstrative rights to do this. Can this be accomplished
without giving the local machine admin rights. I am sorry if this question
has been answered before but i have not been up here in a while.

View 1 Replies View Related

Has Anyone Ever Used An MS ACCESS DB In Conjunction With A MS SQL DB??

May 29, 2008

I want to start off by saying I am lacking when it comes to an indepth knowledge of databases and programming. I contracted with a major company to program a site that has major social networking components to it and other higher level applications. The site was suppossed to be built to handle thousands and eventually millions of people. We already have thousands of people. I recently found out that they used a MS SQL DB in conjunction with an ACCESS DB. I have had conversations with 3 other developers and they cannot come up with a reason why this company would have done this. This is a major company who has years of experience. I have to believe there was some advantage to doing it this way. So far I have not really seen any issues in the performance of it, but have not been able to get an answer to why they would have done it this way. Does anyone have any thoughts on this? It would be much appreciated. Thank you...

View 4 Replies View Related

Ordering In Conjunction With Unions

Oct 7, 2004

Why does this not work? When I run this query in Query Analyzer, I get the error "Incorrect syntax near the keyword 'UNION'." This seems simple enough...


SELECT * FROM SalesLead WHERE Age = '50' ORDER BY FirstName

UNION ALL

SELECT * FROM SalesLead WHERE Age = '60' ORDER BY FirstName


Thanks for any advice

Aaron

View 4 Replies View Related

Reportviewer Control (from VS 2005, In Conjunction With SQL Reporting Services)

Aug 2, 2007

I have a report (stored procedure) that I have set up in SQL 2005 Reporting Services. I've designed this report (using SQL server business intelligence studio), and several other reports, thinking that running totals or summing may be the issue, but it hasn't been. The latest iteration has been just a display of product info, about 100 records, no fields formatted or summed. Very very simple, straight-forward report. If I go to the Report server & upload the rdl file, it displays fine, performs as it should, paging & exporting - everything works fine. The issue comes up when in a web app, I put a Reportviewer control on the page, and call the report.

It works, sort of.

Originally, I had written the page using ASP.NET AJAX Enabled web project, and I had been using the Tab Container on the page. What happens is when I open it on that tab (I am using AJAX Tab panels, which had been working fine without this behavior prior to finally getting the reportviewer working), and the report displays, the "e" on Internet explorer at the top of the tab now flickers, like the page is reloading. It also runs the CPU up to 100% on the computer and although I can go from tab to tab in it (I am using AJAX tab panels in the page), it will take like up to a minute to go to the next tab. I'm not doing anything really data-intensive on those tabs, and they had been functioning fine prior to putting in the report viewer (i.e. they weren't flickering & clocking the CPU).

Thinking that the Tab Container may be the issue, I created just a plain AJAX Enabled web project and put the same reportviewer on it. Same performance. It'll display the report, and then take the system up to 100% and stay there until I kill the browser.

After that, I did just a plain old ASP.Net web project and put the report viewer control on it. Same result. The report will display, but as soon as it does, the "e" on Internet Explorer tab starts flickering and you see the CPU go to 100% and stay there. I've left it for 20-30 minutes with no change. It appears as if the page is constantly refreshing.

Thinking that the issue may be related to having the reportviewer report hard coded in the app, I put a button on the page, and assigned the button to put in the report. It displays, but it again runs the CPU up to 100% and stays there.

I thought that having Asynch = True (run the report asynchronously) might be the issue, but setting it to false made no difference.

I eventually have to kill the page to do anything, because it has the system up to 100%.

The code I am using on this page follows:

Here's the code in the codefile:

Private Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
If Not Page.IsPostBack Then
Me.ReportViewer1.Visible = False
End If
ReportViewer1.ServerReport.ReportPath = ""

End Sub

Protected Sub Button1_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles Button1.Click
ReportViewer1.Visible = True
ReportViewer1.ServerReport.ReportPath = "/BA10listing"

End Sub

The code in the aspx part of the page:

<%@ Page Language="VB" AutoEventWireup="false" CodeFile="Default.aspx.vb" Inherits="_Default" %>

<%@ Register Assembly="Microsoft.ReportViewer.WebForms, Version=8.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a"
Namespace="Microsoft.Reporting.WebForms" TagPrefix="rsweb" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
<title>Untitled Page</title>
</head>

<body>
<form id="form1" runat="server">
<div>
<asp:Button ID="Button1" runat="server" Text="Button" />
<rsweb:ReportViewer ID="ReportViewer1" runat="server" Font-Names="Verdana" Font-Size="8pt" Height="400px" ProcessingMode="Remote" Width="400px" AsyncRendering="False" ShowDocumentMapButton="False">
<ServerReport ReportPath="/BA10listing" ReportServerUrl="http://mycomputer/ReportServer$SQL2005/" />
</rsweb:ReportViewer>
&nbsp;

</div>
</form>
</body>
</html>


.... so you can see there's a lot going on here. The report returns ~100 records or so, no calculations, no summation, no grand totals. Basically a "nothing" report, just listing product info data.

In SQL Reporting Services in the web browser, this report displays fine, no problems. It's only when I call it from the Reportviewer inside a web page that it hangs.

Any idea why reportviewer might make this act this way?

My system is running Windows XP, VS 2005, I have both SQL 2000 and SQL 2005 on this same box. I have a server that has both SQL 2000 & SQL 2005 on it as well, and the behavior is the same for both, whether I run the web page with the Reportviewer control on it with the report being on the local system, or the remote system.

Any help or advice would be very much appreciated.

Thanks!!!

SC

View 23 Replies View Related

Get New Database Created Then Running Script To Created Tables / Relationships

Jun 29, 2015

trying to get a new database created then running a script to created the tables, relationships, indexes and insert default data. All this I'm making happen during the installation of my Windows application. I'm installing SQL 2012 Express as a prerequisite of my application and then opening a connection to that installed SQL Server using Windows Authentication. 

E.g.: Data Source=ComputerNameSQLEXPRESS;Initial Catalog=master;Integrated Security=SSPI; Then I run a query from my code to create the database eg: "CREATE DATABASE [MyDatabaseName]".

From this point I run a script using a Batch file containing "SQLCMD....... Myscriptname.sql". In my script I have my tables being created using "Use [MyDatabaseName]   Go   CREATE TABLE [dbo].[MyTableName] .....". So question is, should I have [dbo]. as part of my Create Table T-SQL commands? Can I remove "[dbo]."? Who would be the owner of the database? If I can remove the [dbo]., should I also remove dbo. from any query string from within my code?

View 3 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

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

Rollback Will Drop Created Tables And Drop Created Tables In Transaction..?

Dec 28, 1999

Hi folks.

Here i have small problem in transactions.I don't know how it is happaning.
Up to my knowldge if you start a transaction in side the transaction if you have DML statements
Those statements only will be effected by rollback or commit but in MS SQL SERVER 7.0 and 6.5
It is rolling back all the commands including DDL witch it shouldn't please let me know on that
If any one can help this please tell me ...........Please............
For Example
begin transaction t1
create table t1
drop table t2

then execute bellow statements
select * from t1
this query gives you table with out data

select * from t2
you will recieve an error that there is no object

but if you rollback
T1 willn't be there in the database

droped table t2 will come back please explain how it can happand.....................

Email Address:
myself@ramkistuff.8m.com

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

Job Created Using SQL DMO Cannot Be Run

Mar 22, 2001

I've created a job using SQL DMO (in VB6) but it fails to run. When try to manual start the job from the Enterprise Manager, it gives error "cannot start job because it does not have any job server(s) defined."

Here is the code :

Dim oSQLServer As New SQLDMO.SQLServer
Dim oJobServer As New SQLDMO.JobServer
Dim oJob As New SQLDMO.Job
Dim oJobSch As New SQLDMO.JobSchedule
Dim oJobStep As SQLDMO.JobStep

oSQLServer.Connect "mc", "sa", ""

oJob.Name = "JOB_Backup"
oSQLServer.JobServer.Jobs.Add oJob

Set oJobStep = New SQLDMO.JobStep
With oJobStep
.Name = "Step 1"
.StepID = 1
.DatabaseName = "master"
.SubSystem = "TSQL"
.Command = "BACKUP DATABASE [medco] TO DISK = 'E:Projectmedco.BAK' With INIT"
.OnFailAction = SQLDMOJobStepAction_QuitWithFailure
.OnSuccessAction = SQLDMOJobStepAction_QuitWithSuccess
End With
oJob.JobSteps.Add oJobStep
oJob.StartStepID = 1

'Set the schedule.
With oJobSch
.Name = "Schedule 1"
.Schedule.FrequencyType = SQLDMOFreq_Daily
.Schedule.FrequencyInterval = 1
.Schedule.ActiveStartDate = "20010315"
.Schedule.ActiveStartTimeOfDay = "150800"
.Schedule.ActiveEndDate = SQLDMO_NOENDDATE
.Schedule.ActiveEndTimeOfDay = SQLDMO_NOENDTIME
End With
oJob.JobSchedules.Add oJobSch

oSQLServer.DisConnect

Set oJobStep = Nothing
Set oJobSch = Nothing
Set oJob = Nothing
Set oSQLServer = Nothing

Something is missing but ?

Thanks for all your helps in advance,
Ben

View 3 Replies View Related

Need Identity Value Of New Row Created

Jan 6, 2004

I'm buildng an application using the ADO.NET OleDB providor in order to maintain back end compatabiity with both SQL Server and Access Jet4.0. I need to get the Identity key of the new row created as a result of the following insert statement.

OLEDB COMMANT TEXT:
"insert into tblPerson (LastName,FirstName,SSN,BirthDate,Family) values( ?, ?,?,?,?)";

I assume I need to add a select statement immediately following the insert. Can anyone help?

PS - not using stored procedures due to Access jet4.0 limitation

View 5 Replies View Related

How Leave Db With 1 Ldf While It Was Created With 2 Ldf ?

Jan 18, 2002

I want to remove 2 big ldf files (400 mgb and 300 mgb) and start db with only one ldf.
I tried sp_attach_db specifing only mdf file but geting errors
-------
microsoft help PRB: sp_attach_single_file_db Does Not Work for Databases with Multiple Log Files (Q271223)
..... You cannot attach a database that has been created with multiple log files without also attaching all the log files.
----

how can I remove those big ldf files and create new ldf (defult(1mgb)

View 1 Replies View Related

Why Are My Tables Not Being Created?

May 7, 2008

This procedure runs and I see my GM names come up one at a time but I get no tables created.

Sorry about the sloppy code - I'm not a real pro.

declare @@GM Char(100)
declare @SQL VarChar (2000)
Declare spot cursor scroll for
select GM from BIM_Historical_Performance.dbo.Performance_Master
open spot
fetch first from spot
into @@GM
While @@Fetch_Status =0
BEGIN

set @SQL = 'select Comp, Billto, Cust_name as Customer, Branch, BAC, [MgMt_Type], BondValue as Bondbucks , BondValueAlloc as Allocbucks, c1 as Curcode, u1 as CurUnderP$, s1 as Cur3mthBIMsales, p1 as performance, I1 as Inside, [IS_since] as Insidesince, O1 as Outside, [OS_since] as Outsidesince, c2 as CodeM-1, c3 as CodeM-2, c4 as CodeM-3, c5 as CodeM-4 ,c6 as CodeM-5, GM into ' +@@GM + ' from BIM_Historical_Performance.dbo.Performance_Master where BIM_Historical_Performance.dbo.Performance_Master.gm = ' +@@GM

EXEC (@Sql)
Fetch NExt from spot
End

View 1 Replies View Related

HELP:I Want To Know Who Had Created The New Tables

Oct 31, 2005

I want to know who had created the new tables,How can I achieve it?
Can I know it by using the sysobjects table?

View 7 Replies View Related

How Can I Know Who Had Created The Table In My DB?

Dec 20, 2005

How Can I know who had created the table in my DB?
May I log it?

View 3 Replies View Related

User Created DBs

Jul 1, 2006

Hi,

How can i get the names of user created databases?

select Distinct (name) from sysobjects where xtype = 'U', i know this statement for tables but is there a statement for Databases?

thanks

View 5 Replies View Related

No Tables Created....

Feb 20, 2008

Hi everyone.. I have a big problem.. :p

I have created a installer for my application and database.
When I run the installer it only creates the database but no tables created. But in some other workstation it works fine. I dont know what causes this problem....

Please guide me.

RON
________________________________________________________________________________________________
"I won't last a day without SQL"

View 10 Replies View Related

BCP - File Is Not Getting Created

Nov 5, 2007



Hi all,

I have been trying to extract table data into file but its not getting extracted. I am using following command to run.


exec spGetIPAddress @ip = @servername output


select @SQL = 'bcp '

+ char(34)

+ ' select Field from ['

+ @DatabaseName

+ '].[dbo].Temp_ExtractSR39'

+ ' order by Field'

+ char(34)

+ ' queryout '

+ @RenamePathAndFile

+ ' -T -c -CACP -S'

+ @servername


exec master..xp_cmdshell @SQL, no_output

Is there any setting need to be done at database level? or any setting for Sql server?

Thanks in adavance,
Anshu


View 3 Replies View Related

What To Do With Pkgs Once Created In BIS?

Mar 6, 2007

Hi,

I have been in the process of creating some new pkgs in BIS. My question is, once I am done writing the pkgs, what next?

That is, how do I get the pkgs into SQL Server, and how do I schedule them to run?

Also, what if I have the following scenario:

I have created a new SSIS pkg that has several EXECUTE DTS 2000 tasks in them. The DTS packages that are called from the EXECUTE DTS 2000 task are stored in the database under "Legacy". These should still run OK once I "load" the packages to SQL Server 2005, yes?

Where do the SSIS packages "live" in SQL Server 2005? That is, where can I view them.

Thank you!!



View 1 Replies View Related

UDT Not Being Created At Subscriber

Nov 10, 2005

Hi,

View 4 Replies View Related

Database Is Not Being Created

Apr 10, 2006

Hi there.

I have generated an SQL Script to script me a database, stored procs, tables, foriegn keys and users, as well as Create command and drop objects.



however it seems that it is not creating the database, if an existing database does not exist, or if it does after it has been dropped. I get this error:

Could not locate entry in sysdatabases for database 'db_name_something'. No entry found with that name. Make sure that the name is entered correctly.


This is the SQL:

/****** Object: Database SafeHands Script Date: 10/04/2006 02:05:30 ******/
IF EXISTS (SELECT name FROM master.dbo.sysdatabases WHERE name = N'db_name_something')

DROP DATABASE [db_name_something]


CREATE DATABASE [db_name_something] ON (NAME = N'db_name_something_Data', FILENAME = N'C:Program FilesMicrosoft SQL ServerMSSQLdatadb_name_something_Data.MDF' , SIZE = 1, FILEGROWTH = 10%) LOG ON (NAME = N'db_name_something_Log', FILENAME = N'C:Program FilesMicrosoft SQL ServerMSSQLdatadb_name_something_Log.LDF' , SIZE = 1, FILEGROWTH = 10%)
COLLATE SQL_Latin1_General_CP1_CI_AS

..

..



any ideas where I am going wrong?

I know that I do not have the "GO" command, however I am trying to run the entire script from C# 2.0, using SQL Server 2000 SP4, so I have read the entire script into a string array, and split each line from the word "GO" as otherwise, I would get an error.

Many thanks

View 3 Replies View Related

Dependency Not Created

Dec 5, 2007

--The Dependency row is not created!

-- I have a procedure "Example 1".

-- When I look at the sys.sql_dependencies I didn't find a row with Table1 dependency.

--If I write the procedure like "Example 2" the dependency Table1 exists in sys.sql_dependencies.

--

--DEFENENTLY A BUG. CAN YOU FIX IT?

--I REALLY NEED IT!!!!!!



Create table Table1 (id int);

GO

--Example 1

CREATE procedure a

as

create table #Test(id int)

Insert into #test

Select id from Table1

DROP TABLE #test;

GO

Select * from sys.sql_dependencies where object_id=object_id('a');

GO

--Example 2

CREATE procedure c

as

Select id into #test from Table1

DROP TABLE #test;

GO

Select * from sys.sql_dependencies where object_id=object_id('c');

DROP PROCEDURE c

DROP PROCEDURE a

DROP TABLE Table1

View 1 Replies View Related







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