Passing A Specific Cursor Record To A Function
Hello,
Is it possible? Can I select a specific record of the cursor to be
sent to a seperate function to do all the computations etc.?
Regards,
VS
View Complete Forum Thread with Replies
Related Forum Messages:
How To Select Specific Record.
Group_Code *****Station_nbr*****Beg_Eff_Date*****End_eff_date 00000002 D01G00733 1/1/2007 8/31/2007 00000002N D01G00733 4/1/2007 8/31/2007 00000002W D01G00733 1/1/2007 12/31/2007 For the report I just want to be able to pick up the first and the last line. Using dbo.Station_group Table Thank you for the help
View Replies !
Passing A Parameter To A USE Command Within A Cursor
Hi everyone I am trying to pass a parameter to a USE command within the body of a cursor. I keep getting an error. Here is my code. Code Snippet DECLARE @SQLText AS NVARCHAR(4000) Declare @SQLText2 as NVARCHAR (2000) DECLARE Cursor_Trial CURSOR FOR SELECT name FROM sys.sysdatabases order by name Declare @name as varchar(255) Open Cursor_Trial FETCH NEXT FROM Cursor_Trial INTO @name WHILE @@FETCH_STATUS = 0 BEGIN Use @name --------This is where I'm getting the error Set @SQLText2 = @name select @SQLText2, * from sys.database_principals where type_desc='DATABASE_ROLE' and name = 'xxxxx' FETCH NEXT FROM Cursor_Trial INTO @name END CLOSE Cursor_Trial DEALLOCATE Cursor_Trial As you can see I am trying to pass the next database name into the body of the cursor so that the query will pull the role information only for the current database in the loop. Any thoughts or tips? Is there a better way to accomplish what I'm trying to do here?
View Replies !
Want To Query One Specific Record From Database Table
I have two tables in my database: order_id with fields order (text) and comp_ID (int) and another table called customers with comp_ID (int) and company name (text) and other company information fields. The link between the two tables is the comp_ID. With every order that's made the company that made the order is stored with it in the order_id table. If I type in the order id (text), I want to be able to use the order id to search the order_id table and find out what the comp_ID of the company that made that order is. Then use that comp_ID to pull up the record of company information from the customers table with the same comp_ID. Is there some way to do this in one query? Or how do I accomplish this?
View Replies !
Can't Fetch Record From Cursor
Hi, I'm relatively inexperienced in sql, and am having trouble interpreting the behavior of a cursor in some code I have inherited. When there is a record in both the Filters and FilterElements tables, the fetch_status is 0. If there is a record in Filters, but no child record in FilterElements, the fetch_status is -1. Since the tables are joined with a RIGHT OUTER JOIN, even when there is no corresponding record in FilterElements, a record is returned (I have verified running the select in a query window). But when used in a cursor, the record is not fetched. The fetch_status is -1. Can anyone tell me why the fetch doesn't work in this case. Thanks ---- DECLARE @CreatedByUser nchar(100), @WorkflowIDs varchar(50); DECLARE @MyVariable CURSOR; SET @MyVariable = CURSOR FOR SELECT isnull(Filters.WorkflowIDs, ''), isnull(FilterElements.CreatedByUser, '') FROM Filters RIGHT OUTER JOINFilterElements ON Filters.ItemID = FilterElements.FiltersItemID WHERE FiltersItemID = @FilterID; OPEN @MyVariable;FETCH NEXT FROM @MyVariable INTO @WorkflowIDs, @CreatedByUser;
View Replies !
Update Record In A Cursor
Please tell me how to code the Update of the current cursor record as one would do using VD/ADO : VB: Table("Fieldname") = Value ---------------------------------------------------------- Declare @NextNo integer Select @NextNo = (Select NextNo from NextNumbers where NNId = 'AddressBook') + 1 --Create a Cursor through wich to lo loop and Update the ABAN8 with the corrrect NextNo DECLARE Clone_Cursor CURSOR FOR Select ABAN8 from JDE_Train.trndta.F0101_Clone Open Clone_Cursor Fetch Next from Clone_Cursor WHILE @@FETCH_STATUS = 0 BEGIN Select @NextNo = @NextNo + 1 Clone_Cursor("ABAN8") = @NextNo Update Clone_Cursor FETCH NEXT FROM Clone_Cursor END CLOSE Clone_Cursor DEALLOCATE Clone_Cursor GO
View Replies !
Passing Variable On To Next Record
I am running a query in with my daily import job that lets me know if a duplicate record was imported into the system. If so I want to setup my email table to mail me the following information. My code works fine except the value of the variable @ID is only giving me the first record in the set. How do I pass it on to the next record? I get the right number of rows inserted into the email table but the @ID variable is the same for all 3. Drop Table #SER1 Select id#, Colx=Count(*) Into #SER1 From Business Group By id# Having Count(id#) > 1 Declare @ID Varchar (4) Select @ID = ID# from #SER1 INSERT INTO Email ( [To], [Subject], [message], [Table], TableUKey, TableSource ) SELECT 'Firstname.Lastname@Company.com', 'Duplicate ID# Imported', 'ID# ' + @ID + ' has been imported multiple times ' + ' on ' + cast( getdate() AS varchar(30)) + '. You need to remove the record and rerun the import.', 'Daily Import', @ID, 'Daily Import' FROM #SER1
View Replies !
'One Table' Record To Separate 'two Or Three Tables' Using Cursor?
I would like to 'one table' record to separate 'two or three tables' . I just know use the DTS , try to import and export again and agian. So trouble. Could you give me some suggestions for me? For example , 'Cursor' write in new table . But I try to SQL Server Books Online which is not suitable for me solving problems. One table separate two or three tables. Can you wirte the detail example for me? Thx a lot.
View Replies !
Using A Cursor In A Function
I'm creating a user-defined functtion, with a cursor in it.... I really do not understand the errors that I am getting when I try to run my query : Server: Msg 444, Level 16, State 1, Procedure BusStatus_chk, Line 48 Select statements included within a function cannot return data to a client. Server: Msg 444, Level 16, State 1, Procedure BusStatus_chk, Line 66 Select statements included within a function cannot return data to a client. Server: Msg 444, Level 16, State 1, Procedure BusStatus_chk, Line 69 Select statements included within a function cannot return data to a client. The Create procedure statement is as follows: CREATE FUNCTION DBO.BusStatus_chk( @busreg as varchar(10), @wday as tinyint, @stime as smalldatetime, @endtime as smalldatetime ) RETURNS int AS BEGIN DECLARE @totaltime smallint DECLARE @cnt int DECLARE @thisDur smallint Set @cnt = (Select Count(*) from Bus_Status where Bus_Reg = @busreg AND week_day = @wday) IF @cnt > 0 BEGIN Select @thisDur = DATEDIFF(mi, @stime, @endtime); Select @totaltime = SUM(DATEDIFF(mi, Start_time, end_time)) FROM Bus_Status WHERE Bus_Reg=@busreg AND week_day=@wday END; IF @totaltime !> 0 BEGIN Select @totaltime=0; END; IF @thisDur !> 0 BEGIN Select @thisDur = 0 END; Select @totaltime = @totaltime + @thisDur IF @totaltime > 600 BEGIN RETURN 0 END; DECLARE bustimes_cur CURSOR FOR SELECT * FROM Bus_Status WHERE Bus_Reg=@busreg AND week_day=@wday AND @stime BETWEEN start_time and end_time OPEN bustimes_cur FETCH FIRST FROM bustimes_cur WHILE @@FETCH_STATUS = 0 BEGIN FETCH NEXT FROM bustimes_cur END Select @@CURSOR_ROWS IF @@CURSOR_ROWS > 0 BEGIN RETURN 0 END; CLOSE bustimes_cur DEALLOCATE bustimes_cur DECLARE busEndtimes_cur CURSOR FOR SELECT * FROM Bus_Status WHERE Bus_Reg=@busreg AND week_day=@wday AND end_time BETWEEN @stime and @endtime OPEN busEndtimes_cur FETCH FIRST FROM busEndtimes_cur WHILE @@FETCH_STATUS = 0 BEGIN FETCH NEXT FROM busEndtimes_cur END; IF @@CURSOR_ROWS > 0 BEGIN RETURN 0 END; CLOSE busEndtimes_cur DEALLOCATE busEndtimes_cur RETURN 1 END --END OF FUNCTION busStatus_chk :confused: :confused: PLEASE HELP!!!
View Replies !
Using A Cursor As A Function Parameter
I've created a function that converts the rows of a column into a delimited string using a passed cursor and delimiter character. In the past I did this in Oracle and called it as shown in the following example: SELECT Table1.ID, Table1.FirstName, Table1.LastName, fnDelimitRows(CURSOR(SELECT Table2.CourseName FROM Table2 WHERE Table2.StudentID = Table1.ID), ',') AS AssignedCourses FROM Table1 23 John Smith CS101,MT200,BIO100 43 Julio Johnson CS200,ENG100,MT300 How would I pass a cursor into a function in SS like I did above in Oracle? Thanks!
View Replies !
Split Function With Cursor
Hi, I am trying to write a stored procedure that takes a comma separated letter. I have a split function that returns the splitted letters. I have select some values from the tables in the database where the title starts with each splitted letter. I thought I should use cursor that contains each letter and in the while loop i put my select statement with the conditions. Is this the correct way. Or are there any ideas for this? thanks, Regards, shakthi
View Replies !
Passing Columns To CLR Function
Hello, I am trying to send to colums to SQL CLR function and get some results. I want the CLR code be like: Code Snippet public void DoSomething(SqlDouble[] a, SqlDouble[] b, out SqlDouble x, out SqlDouble y, out SqlDouble z) { //Do Something... x = .... y=... z=... } I want to call this code from SQL code: Code Snippet create table #Temp (float a,float b) declare @x float declare @y float declare @z float exec dbo.DoSomething(a,b,@x,@y,@z) ---???? Do someone have an idea?
View Replies !
Passing Parameter In Function
I have to pass 3parameters in function, @begindate,@enddate and @group_type.. but in @group_type should be - state,zipcode and country from salestable inview :vwstzipcont create view vwstzipcont as select distinct s2.stype,s3.itemnmbr,s2.docdate,s3.state,s3.zipcode,s3.country from Salestable s3 left outer join (select distinct stype,docdate from salesdisttable) s2 on s2.stype = s3.stype where s2.soptype = 2 go create function mystzipcont ( @begindate datetime, @enddate datetime, @group_type char(70)) RETURNS TABLE AS RETURN (Select distinct t.docdate,t.itemnmbr,t.index,t.group_type from ( select distinct vs.docdate,vs.itemnmbr, p.index From Pubs P inner join vwstzipcont vs on vs.index = p.index Where (vs.docdate between @begindate and @enddate) and @group_type ) as t order by t.itemnmbr,t.docdate end how can i assign @group_type variable or t.group_type? in s3.state,s3.zipcode,s3.country can anyone tell me? what condition should be in where clause for this variable? thanks
View Replies !
Passing Table Name As Parameter To Function
Hi all. I'm writing reports in Rep. Services that reads data from Dynamics NAV (Navision). In NAV data are stored by company and this is implemented by using the company name as prefix to the table name. This means that in a NAV database with three companies (lets call these companies A, B and C) we will have three tables with customers. The table names will be A$Customer, B$Customer and C$Customer. Now to my problem: I wan't to write one report where I can choose company. I do not want to use a stored procedure. I want to use a function so I can use the function in select statements and join several functions to build up a report that needs data from several tables. Is there some way to pass the table name or a part of the table name to a function that returns the content of the actual table? I know I can pass parameters that I can use in the where clause, but is it possible to do it with the table name. Or is there any other way to solve this. All ideas are welcome. Thanks.
View Replies !
Passing A Suquery To A Function As A Parameter
How would one pass a subquery to a function as a parameter? I have a function, f_Split that returns a table and has two parameters @List varchar(max) and @Delim char(1). I'd like to use it to normalize rows in a table and return the results for use in a report. I tried the following: SELECT * FROM dbo.f_Split((SELECT Code FROM Codes WHERE ID = 10), '|') I'm getting a syntax error for the subquery. Could anyone show me the proper way to pass a subquery to a function, even if the function is different from what I have defined here. Thanks, DD
View Replies !
In A Query, Passing Data To A .net Function
Hello, I have just migrated some databases from sql2000 to sql2005 and I just read about the possibility to use CLR-based functions within a query. This may be really nice for me, since I often need complex functions and I often cannot write them in TSQL. But my question is: what kind of data can I pass in a sql query to a .net function? Obviously, simple data, like numbers and strings from within a record can be passed. But would it be possible to go further, like passing a complete record, or even passing a set of records? How far could I go in sql when using .net function? Thanks to inform me about the available power of this new feature.
View Replies !
Passing Variable To Table Function In Join
Hello, thanks in advance for reading this. I am having difficulty trying to get a statement to work. There is a MAIN table: ItemNo int identity(1,0), ItemType tinyint There is a WETPAINT table: ItemNo int, Color varchar(20) There is a DRYPAINT table: ItemNo int, Color varchar(20) Now, what I want to do is JOIN the MAIN table to either the WETPAINT table or the DRYPAINT table depending on the value of MAIN.ItemType So I created a table function called getTable: CREATE FUNCTION [dbo].[gettable] ( @ItemType int = 1 ) RETURNS @thistable TABLE ( Color varchar(20) ) AS BEGIN if @ItemType = 1 insert into @thistable (color) select color from WETPAINT if @ItemType = 2 insert into @thistable (color) select color from DRYPAINT RETURN END This is all fine and dandy if I iterate through the MAIN table one row at a time, but how can I JOIN the tables, like: SELECT MAIN.ItemNo, a.Color FROM MAIN INNER JOIN gettable(Main.ItemNo) as a ON a.ItemNo = MAIN.ItemNo Obviously, there is more than one field in the DRYPAINT and WETPAINT tables, and there is a need to have both tables instead of combining them into one. Any help in how to create a table alias by passing a value from the select statement would be greatly appreciated! Thanks again. PS -- I am trying to create a view with this, so I can't use variables and iterate through the MAIN table one row at a time.
View Replies !
Passing Variable To String Compare In Function
I have created a function with: set ANSI_NULLS ON set QUOTED_IDENTIFIER ON GO ALTER FUNCTION [dbo].[fn_concat_boxes](@item varchar, @week int) RETURNS VARCHAR(100) AS BEGIN DECLARE @Output varchar(100) SELECT @Output = COALESCE(@Output + '/', '') + CAST(quantity AS varchar(5)) FROM flexing_stock_transactions WHERE item = @item AND week = @week GROUP BY quantity ORDER BY quantity RETURN @Output END how can I pass the variable @item correctly for the string comparison WHERE item = @item AND week = @week to work correctly please? WHERE item = '@item' AND week = @week won't work and WHERE item = @item AND week = @week won't work.
View Replies !
Passing MS SQL2005 Query Result Into Javascript Function
I'm selecting the last latitude & longitude input from my database to put into the Google maps javascript function. This is how I retrieve the longitude: <asp:SqlDataSource ID="lon" runat="server" ConnectionString="<%$ ConnectionStrings:LocateThis %>" SelectCommand= "SELECT @lon= SELECT [lon] lon FROM [location] WHERE time = (SELECT MAX(time) FROM [location] where year < 2008)"> </asp:SqlDataSource> I wish to input the latitude & longitude into the JAVASCRIPT function (contained in the HTML head before the ASP) something like this: var map = new GMap2(document.getElementById("map"));var lat = <%=lat%>;var lon = <%=lon%>;var center = new GLatLng(lat,lon);map.setCenter(center, 13); However, lat & long do not contain the retrieved result but rather a useless System.something string. How do I assign the retrieved results to these variables and port them over to Javascript as required? Many thanks!
View Replies !
Problem Passing UDF Scalar Result To UDF Table Function
I'm having difficulties invoking a user defined table function,when passing to it a parameter that is the result of anotheruser defined function.My functions are defined like so:drop function dbo.scalar_funcgocreate function dbo.scalar_func()returns intbeginreturn 1endgodrop function dbo.table_funcgocreate function dbo.table_func(@p int)returns tablereturn (select @p as id )goGiven the above, I can do the following:Select from the scalar function works:1> select dbo.scalar_func() as scalar_result2> goscalar_result-------------1Selecting from the table function works, if i pass aconstant value (or a variable)1> select id from dbo.table_func(1)2> goid-------------1But, if I try to pass the table function the return valueof the scalar function in one call, it doesn't work,producing the following error:1> select id from dbo.table_func( dbo.scalar_func() )2> goMsg 170, Level 15, State 1, Line 1Line 1: Incorrect syntax near '.'.What am I missing here?Thanks kindly
View Replies !
Problem Passing A Variable Into A Table-valued Function
Hi, i am encountering a problem in a stored procedure when a pass a variable value into a table-valued function. The table-valued function is named getCurrentDriver and has 1 attribute: car-ID. The syntax is as follows: select car.id, car.licenceNumber, car.brand, car.model, (select driverName from getCurrentDriver(car.id)) as driverName from car When I try to compile I get following error on the line of the function: Incorrect syntax near '.' The database version is SQL Server 2000 SP3. What am I doing wrong? Is there a workaround for this error?
View Replies !
Passing Parameter Query From SQL Function To Access Project Report
I can pass a parameter from an Access Query to an Access Report (MDB) by entering [Select Date] in the Query criteria and by placing an unbound control with a control source =[Select Date] on the report. I can't get this to work from a SQL Function Criteria to an unbound control on the Access Data Project Report. In the Function Criteria, I enter @SelectDate. In the Report control, I enter @SelectDate and it gives me an 'Invalide Column Name' error. Any idea how I can pass a parameter from a SQL Function to an ADP report? THANKS! p.s. I tried searching for other postings on this without any luck.
View Replies !
What Function Can Create A Record Automatically
In the table, there is a record which has several field. every month, the function will create a same record. that means, the first month, one record. the secord month, two reocrds, ..... for a years. will have same 12 record. so what function can do this? Thanks.
View Replies !
Fetching A Record From The Database Within A Function.
Can I do something like this in RS - I would like to call a function in a calculated field like =code.GetNHW(Fields!id1.Value,Fields!date1.Value) where the GetNHW() function would return a double value based on some conditions- The code I would like to write in Code window- Public Function GetNHW(ByVal ID As Integer, ByVal attDate As Date) As Double Dim dsDTConfig As New DataSet Dim NHW As Double dsDTConfig = GetDS("tblEmployee_DailyTimingsConfig", "id=" & ID & " and '" & attDate & "' between configStartDate and configExpiryDate", False) If dsDTConfig.Tables(0).Rows(0)("allowUnscheduledBreaks") = True Then NHW = 0.01 ElseIf dsDTConfig.Tables(0).Rows(0)("allowUnscheduledBreaks") = False Then NHW = 0.05 End If Return NHW End Function What I am looking for is - I would want to get the record(dataset) within the function from the database and based on the values got, I would check few conditions and calculate NHW. --Anand
View Replies !
Automated Testing | How To &"force&" GETDATE() Function To Return Specific Value?
Hello,Our QA team have running a lot of test scripts (for automated regressiontesting), they run them on the different databases (Oracle/MS SQL).Several of those tests are dependent on the current date/time. In order tobeable to use them efficiently, we changed the current date/time on the QAdatabase server to a specific date/time before starting the scripts, so weare sure the test scripts always run in the same environment.Resetting the date/time of the database server gives us more and moreproblems (OS problems, backup/ virusscan, ...).It is possible to fix the problem with SYSDATE function on Oracle by settingFIXED_DATE init parameter.Is it possible to 'change' the current date/time on 'database' level,instead of on OS level for MSSQL2000?Do you know other means to do such things?Thanks in advance,Konstantin
View Replies !
ContainsTable Function Searching Only One Column Per Record
Hello all, I am using the ContainsTable function to search a database from my (c#) app. This works relatively well and all fields of the table are indexed and searched. That is, any column, but per record only one column. What I mean is this: when searching for "chris 2007", I want to retrieve all items where author contains chris and year contains 2007. Currently, a search for chris brings up all items where author (or any other field) contains chris, a search for 2007 works as well, but chris 2007 fails as there is no -one- field where chris and 2007 are located. Can anybody help me achieve this? My code is: Code Block SELECT FT_TBL.ID, FT_TBL.Type, FT_TBL.Author, IsNull(FT_TBL.Author, FT_TBL.Editor + ' (Ed.)') AS CorrectedAuthor, FT_TBL.Editor, FT_TBL.Title, FT_TBL.Abstract, FT_TBL.Comments, FT_TBL.Year, FT_TBL.City, FT_TBL.Publisher, FT_TBL.ISBN, FT_TBL.Pages, FT_TBL.Journal, FT_TBL.Issue, FT_TBL.Hyperlink, FT_TBL.Tags, KEY_TBL.RANK FROM Sources AS FT_TBL INNER JOIN CONTAINSTABLE(Sources, *, @searchQuery) AS KEY_TBL ON FT_TBL.ID = KEY_TBL.[KEY] ORDER BY KEY_TBL.RANK DESC; What am I doing wrong? Thanks in advance, Chris
View Replies !
SQL Server 2005 SELECT MAX Function For Multiple Columns On The Same Record
Hello, I am trying to figure out how to use the select maximum command in SQL Server 2005. I have already created a database and I have it populate it with multiple fields and multiple records. I Would like to create a new column or field which contains the maximum value from four of the fields. I have already created a column and I am trying to figure out how to use a command or SQL statement which is entered into the computed equation or formula in the properties for this field/column. Any help you can provide will be greatly appreciated! Thank you, Nathan
View Replies !
DMS Log Record Header Structure Function Identifier Values And Definitions
Hi, I'm a SQL Server database developer currently working on a project involving log records extraction. I would like to know where to find information equivalent to "DMS Log Record Header Structure Function Identifier Values and Definitions" for SQL transaction logs (for example: value = 102, would 'add columns to table'). In addition, does SQL Serve have a built-in API to read database (transaction) log without a database connection. Please advise.
View Replies !
Can Logging Be Turned Off On Inserts To A Specific Temp Table From A Specific Sp?
I want to ship 500,000 aged transactions each night to an archive table and delete them from their source table in one or more logical units of work (LUW). Each row is approx 60 bytes and there is only one non clustered index on the source table presently. I'm trying to weigh the pros and cons of 3 alternatives. One of them would basically insert the non-aged rows into tempdb, ship the aged records, truncate the table and then insert the tempdb records back into their source all in the same LUW. For this alternative, I'd at least like to turn off logging when the records get inserted into tempdb as I dont see any value in logging that part of the activity. Is this possible?
View Replies !
Command Line Printing To Specific Printers, And Specific Trays
Hi All, Could you guys please help me with printing reports invoked thru command line/ URL access to print automatically to specific printers and specific trays and also is it possible to set the specific printer and tray as parameters. Any suggestions is appreciated Thanks A lot in advance e,g : http://localhost/reportserver?/testreports/employee sales&UserID='ABC'&LName=Lastname='victor'&rs:Command=Render
View Replies !
How To Select A Specific Value From Dataset To Fill A Specific Cell ?
Hi there ! Thanks for taking the time to read this thread. I don't know whether anyone has this problem, but I am definitely not using the right keywords to search for a thread. My situation is this... I have a dataset that has values to fill cells to multiple tables in a report. However, I only want to select specific data from the dataset to fill textboxes and others. I cannot change the stored procedure, but the sample of the data is shown below:- Row Stat Val 0 dtRpt1 02/01/2005 1 Value1 1 2 Value2 2000 3 dtMailSent 02/28/2005 4 Value3 0 5 Value4 5 6 Value5 658 I know it looks weird, but the row really represents which "row" or textbox is it to fill with the Val. The Stat Column is just a way to make sure that I am filling the right values. so my new report would have multiple tables to denote different categories. In my first table, I tried putting the cells as follows:- (expressions are highlighted in italics and bold) TextBox1 =IIF(Fields!Row.Value =0, Fields!Val.Value,"") Table1 Column1 DetailRow1 =IIF(Fields!Row.Value =1, Fields!Val.Value,"") DetailRow2 =IIF(Fields!Row.Value =2, Fields!Val.Value,"") Table2 Column1 DetailRow1 =IIF(Fields!Row.Value =3, Fields!Val.Value,"") DetailRow2 =IIF(Fields!Row.Value =4, Fields!Val.Value,"") DetailRow3 =IIF(Fields!Row.Value =5, Fields!Val.Value,"") DetailRow4 =IIF(Fields!Row.Value =6, Fields!Val.Value,"") I only expect this report to print out one page holding the previous values. However, it ended up printing like this ---------------------------------------------------------- Table1 Column1 DetailRow1 1 DetailRow2 Column1 DetailRow1 DetailRow2 2000 Table2 Column1 DetailRow1 02/28/2005 DetailRow2 DetailRow3 DetailRow4 Table2 Column1 DetailRow1 DetailRow2 0 DetailRow3 DetailRow4 Table2 Column1 DetailRow1 DetailRow2 DetailRow3 5 DetailRow4 Table2 Column1 DetailRow1 DetailRow2 DetailRow3 DetailRow4 658 ------------------------------------------------------ I tried putting it into the headerrows instead of DetailRows, and it ended up printing the last value. Is there anyway to do this ? print all the values out in one table ? I tried using textboxes, but I think I got my expression wrong. Is this the correct expression ? =IIF((Fields!Row.Value,"Dataset") =1, (Fields!Val.value, "Dataset"), "") and it give me an error The value expression for the textbox €˜textbox5€™ contains an error: [BC30455] Argument not specified for parameter 'FalsePart' of 'Public Function IIf(Expression As Boolean, TruePart As Object, FalsePart As Object) As Object'. Appreciate any advice or suggestion for this scenario ! Thanks! Bernard
View Replies !
Assign Specific Data To Specific Users
I am very early on in developing a website to track issues with projects which is tied to a SQL database. I have my Projects Table, my Users Table, and am creating a third table to track issues. I'm wondering what is the best way to assign specific users to specific data/projects. The user should only be able to view & update the projects assigned to him. He should not be able to see other projects. What is the best way to assign projects/data to the users to make sure they are only viewing their data?
View Replies !
Dynamic Cursor Versus Forward Only Cursor Gives Poor Performance
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 Replies !
Could Not Complete Cursor Operation Because The Set Options Have Changed Since The Cursor Was Declared.
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 Replies !
Join Cursor With Table Outside Of Cursor
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 Replies !
Ways To Make This Work: Several Selectable Related Record For One Main Record.
Hey all! Sorry for the less then descriptive post title but I didn't find a better way to describe it. I'm developing an app in the express editions of VB and SQLserver. The application is a task/resource scheduler. The main form will have a datepicker or weekly overview and show all tasks scheduled per day. The problem is, I've got one or more people assigned to tasks and I wonder what's the best way to design this. Personally, I'd go for one Task table, a People table and a table that provides a link between them (several record per task, one for each person assigned linking TaskID and PplID). However, I don't see a nice way of showing this data to the end user, allowing him to edit/add etc on ONE screen. To fix that the only way I see is just add columns to the Task table for every person with select boxes. This way everything can be done on one simple screen. This obviously does present some future issues. On top of this, which people are available on a day varies and there should be an option to allow a user to set who is available on a specific day. Which would lead me to my first idea and add another table that would provide this. but then I'm having design issues again for the form. I'm kinda stuck atm, can anyone shed some light on this. I'm sure there is an elegant way of doing this but I'm failing at finding it. Thanks in advance, Johan
View Replies !
Query Timeouts When Updating A Record Retrieved Through A Websphere JDBC Datasource - Possible Record Locking Problem
Hi, We're running a Sage CRM install with a SQL Server 2000 database at the back end. We're using the Sage web services API for updating data and a JDBC connection to retrieve data as it's so much quicker. If I retrieve a record using the JDBC connection and then try and update the same record through the web services, the query times out as if the record is locked for updates. Has anyone experienced anything similar or know what I'm doing wrong? If I just use DriverManager.getConnection() to establish the connection instead of the datasource, and then continue with the same code I don't get these record locking problems. Please find more details below. Thanks, Sarah The JDBC provider for the datasource is a WebSphere embedded ConnectJDBC for SQL Server DataSource, using an implementation type of 'connection pool datasource'. We are using a container managed J2C authentication alias for logging on. This is running on a Websphere Application Server v6.1. Code snippet - getting the record thru JDBC: DataSource wsDataSource = serviceLocator.getDataSource("jdbc/dsSQLServer"); Connection wsCon = wsDataSource.getConnection(); // wsCon.setAutoCommit(false); //have tried with and without this flag - same results Statements stmt = wsCon.createStatement(); String sql = "SELECT * FROM Person where personID = 12345"; ResultSet rs = stmt.executeQuery(sql); if(rs.next()){ System.out.println(rs.getString("lastName")); } if (rs != null){ rs.close(); } if (stmt != null) { stmt.close(); } if (wsCon != null) { wsCon.close(); }
View Replies !
|