Errors In Function Code
Feb 2, 2007
Hi,
I'm pretty new to SQL and I'm having trouble with a function, probably just syntax. I'm trying to consolidate several rows of data into a single row text field.
The calling program can use views but not functions so I need to get a table into a view with the consolidated lines.
Also, I would think this could be consolidated to a single view that calls one function. Is that possible, how would I do it?
Thanks for any help,
Steve
VIEW WHERE DATA COMES FROM:
CUST_ORDER_ID | LINE_TEXT
number1 | first line item text
number1 | Second line item text
number1 | Third line item text
number2 | first line item text
number2 | Second line item text
...
VIEW I WANT:
CUST_ORDER_ID | CO_LINES_TEXT
number1 | Second line item text 'crlf' Third Line item text
number2 | Second line item text
FUNCTION CODE: This is the function code with errors
CREATE FUNCTION dbo.tvf_NC_CO_LINES_TEXT (@ORDER_ID VARCHAR(20))
RETURNS @NC_CO_LINES TABLE
(
CUST_ORDER_ID VARCHAR(20) PRIMARY KEY NOT NULL,
CO_LINES_TEXT VARCHAR(1000) NULL
)
AS
BEGIN
DECLARE @COLinesString VARCHAR(1000);
SET @ORDER_ID = CUST_ORDER_ID;
SELECT @COLinesString = COALESCE(@COLinesString + Char(13) + Char(10), '') + LINE_STRING
FROM NC_CO_LINES_STRING
WHERE NC_CO_LINES_STRING.CUST_ORDER_ID = @ORDER_ID
SET @COLinesString = CO_LINES_TEXT
RETURN
END;
GO
ERROR MESSAGES:
Msg 207, Level 16, State 1, Procedure tvf_NC_CO_LINES_TEXT, Line 16
Invalid column name 'CUST_ORDER_ID'.
Msg 207, Level 16, State 1, Procedure tvf_NC_CO_LINES_TEXT, Line 20
Invalid column name 'CO_LINES_TEXT'.
VIEW CODE:
SELECT dbo.CUST_ORDER_LINE.CUST_ORDER_ID, CAST(CAST(dbo.CUST_ORDER_LINE.ORDER_QTY AS INT) AS VARCHAR(2))
+ ' ' + dbo.CUST_ORDER_LINE.PART_ID + ' ' + dbo.PART.DESCRIPTION AS LINE_STRING
FROM dbo.CUST_ORDER_LINE INNER JOIN
dbo.PART ON dbo.CUST_ORDER_LINE.PART_ID = dbo.PART.ID
WHERE (dbo.CUST_ORDER_LINE.LINE_NO > 1)
Steve Bermes
Novae Corp.
View 2 Replies
ADVERTISEMENT
May 14, 2007
set ANSI_NULLS ON
set QUOTED_IDENTIFIER ON
go
/*************************************************************************************
Description: This store procedure is used to return the district's Rubric Report.
Returns:
RubricReport.ReportID
RubricReport.LastUpdate
RubricReport.LastUpdateBy
RubricReportDetail.LocalPerf
RubricReportDetail.GoalMet
RubricReportTemplate.IndicatorNumber
RubricReportTemplate.Topic
RubricReportTemplate.Part
RubricReportTemplate.ILCDComponent
SppTarget.Target
Parameters:
@DataYears
@County
@District
@LastUpdateBy
*/
ALTER PROCEDURE [dbo].[usp_RubricReportGet]
-- Add the parameters for the stored procedure here
@DataYears CHAR(8),
@County CHAR(2),
@District CHAR(4),
@LastUpdateby VARCHAR(50),
@ReportID INT,
@LastUpdate SMALLDATETIME,
@IndicatorID TINYINT,
@IndicatorNumber VARCHAR(5),
@Number VARCHAR(20),
@FYY CHAR(9),
@Part CHAR(1),
@Years CHAR(8),
@maxLastUpdate SMALLDATETIME,
@LocalPerf DECIMAL(5,4),
@GoalMet BIT,
@Topic VARCHAR(100),
@ILCDComponent VARCHAR(50)
AS
BEGIN
-- SET NOCOUNT ON added to prevent extra result sets from
SET NOCOUNT ON;
-- Get the ReportID and LastUpdate values from Rubric Report Table matching
-- County=@County and District=@District
SELECT ReportID, LastUpdate
FROM RubricReport
WHERE (RubricReport.County = @County) AND (RubricReport.District = @District) AND (RubricReport.DataYears = @DataYears)
-- With table SPPIndicator and SppIndicator11Data, find the maximum value of LastUpdate (@maxLastUpdate)
SELECT @maxLastUpdate FROM (SELECT LastUpdate FROM SPPIndicator UNION ALL SELECT LastUpdate FROM SppIndicator11) AS D
IF @maxLastUpdate > (SELECT LastUpdate FROM RubricReport WHERE (RubricReport.County = @County) AND (RubricReport.District = @District) AND (RubricReport.DataYears = @DataYears))
BEGIN
EXEC usp_RubricReportCalc @DataYears, @County, @District, @LastUpdateBy
END
ELSE
SELECT ReportID, LastUpdate, LastUpdateBy
FROM RubricReport
WHERE RubricReport.ReportID = RubricReportDetail.ReportID
SELECT IndicatorNumber, Topic, Part, ILCDComponent
FROM RubricReportTemplate
WHERE RubricReportDetail.IndicatorID = RubricReportTemplate.IndicatorID
SELECT LocalPerf, GoalMet
FROM RubricReportDetail
WHERE SppTarget.IndicatorNumber = RubricReportDetail.IndicatorID
SELECT Target
FROM SppTarget
WHERE SppTarget.Years = @DataYears
END
I have the above created stored proc. which gives the following errors:
Msg 107, Level 16, State 3, Procedure usp_RubricReportGet, Line 69
The column prefix 'RubricReportDetail' does not match with a table name or alias name used in the query.
Msg 107, Level 16, State 3, Procedure usp_RubricReportGet, Line 73
The column prefix 'RubricReportDetail' does not match with a table name or alias name used in the query.
Msg 107, Level 16, State 3, Procedure usp_RubricReportGet, Line 78
The column prefix 'SppTarget' does not match with a table name or alias name used in the query.
How can I resolve these erros?
View 8 Replies
View Related
Dec 12, 2007
SELECT CUSTNO Customer , ORDERNO Order , O_DATE Order Date
FROM cust_order
WHERE O_DATE = 10-20-03 AND EMPO= '%4'
ORDER BY ORDERNO;
please can anybody identify 4 errors
View 5 Replies
View Related
Jan 7, 2005
Hi everyone,
I have a form that is being used by a user, and the form is writing to an sql database, but it gets the "string or binary data would be truncated, the statement has been terminated" error. I realize that this is due to the fact that he filled out a an entry where the respective column length was shorter than what he put in...
I am curious as to how you account for this? What is the industry practice? Is it better to truncate? Make the database columns a huge size? Put in validators for every single control to make sure that the space is an acceptable length? How do you guys account for things that might go wrong when writing to SQL?
Try, Get's?
I am confused as to how to even approach this sort of thing...
Thanks,
View 1 Replies
View Related
Feb 9, 2006
I am importing some data from my IBM DB2 Z/OS mainframe to SQL Server 2005 using the SSIS import wizard. The wizard automatically converted the DB2 string data before trying to store it to SQL Server. The code page that the wizard chose to do its conversion is the 1252 Ansi Latin. However, I am getting the following error on the address field...."one or more characters had no match in the target code page". Can someone suggest another code page? ASCII? IBM 37?
View 3 Replies
View Related
Apr 9, 2007
Hi,
I'm new to SQL Server RS.
I'm getting build errors after writing the following code:
List<ReportParameter> reportParam = new List<ReportParameter>(); reportParam.Add(new ReportParameter("Database", connectionString)); reportParam.Add(new ReportParameter("master_dept", hidMasterDept.Value.ToString().Trim())); reportParam.Add(new ReportParameter("station_id", hidStationId.Value.ToString().Trim())); reportViewer.ServerReport.SetParameters(reportParam)
The error message is as follows:
No overload for method 'ReportParameter' takes '2' arguments
But when I build the page using "Build Page" command from the menu, it builds successfully and then the project build succeeds.
When I modify any other page and build the solution, the same build error for this page occurs again.
Any idea how to resolve this? Been spending a lot of time figuring this out.
Thanks in Advance,
Manjunath HK
View 5 Replies
View Related
Nov 21, 2007
Hi All,
we have a set of packages which has to to be implemented across differnet environments.
the packages invariable uses OLEDB Source/Destination Components.
In these two components the Code Page Property is not Configurable.
so if the package has to be Deployed in a different environment than,where it is Developed it gives a Validation Error.
Is there a Workaround for this problem.
if anybody have faced the problem earlier,please post it.
thanks in advance.
cheers
srikanth
View 1 Replies
View Related
Feb 1, 2008
I created some custom code that will check to see if a file exists on a Windows Share.
Code Snippet
Public Function FileExists(ByVal FileFullPath As String) As Boolean
Try
Dim f As New System.IO.FileInfo(FileFullPath)
Return f.Exists
Catch e As Exception
Return e.Description
End Try
End Function
An example of what I am passing is this:
Code Snippet
\servernamesharenamefilename.txt
I use this code in a TextBox on my Report:
Code Snippet
=IIF(Code.FileExists(Fields!OutPutFileName.Value) = TRUE,"True","False")
I get this error in my report:
Code SnippetSystem.Security.SecurityException: Request for the permission of type 'System.Security.Permissions.FileIOPermission, mscorlib, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089' failed.
at System.Security.CodeAccessSecurityEngine.Check(Object demand, StackCrawlMark& stackMark, Boolean isPermSet)
at System.Security.CodeAccessPermission.Demand()
at System.IO.FileInfo..ctor(String fileName)
at ReportExprHostImpl.CustomCodeProxy.FileExists(String FileFullPath)
The action that failed was:
Demand
The type of the first permission that failed was:
System.Security.Permissions.FileIOPermission
The Zone of the assembly that failed was:
MyComputer
BUT it works on my local machine. Any Ideas?
View 3 Replies
View Related
Jun 6, 2008
Hi all, if have problem to display error message in vb.net that comes from a stored procedure. IF ...... then msgbox "ERROR at Update" returnvalue = SUCCES ELSE Msgbox "Successfull Updated" returnvalue = ERROREND IFHow can I return values from Stored Procedure to VB.NET and then give to User a Message that the Update was successful or not.Thanks to all
View 2 Replies
View Related
Feb 28, 2008
I have written a CLR function in C# to access a sql server different from the current server where I have deplyed the assembly.
DataSet ds = new DataSet();
SqlCommand sqlCmd = new SqlCommand();
sqlCmd.CommandType = CommandType.StoredProcedure;
string connString = "Data Source=SQLSERVER;Initial Catalog=DATABASE;User ID=userid;Password=password;";
SqlConnection sqlConn = new SqlConnection(connString);
sqlCmd.Connection = sqlConn;
sqlConn.Open();
try
{
SqlDataAdapter sda = new SqlDataAdapter();
sqlCmd.CommandText = "StoredProcedureName";
sqlCmd.Parameters.Add("@Param1", SqlDbType.VarChar);
sqlCmd.Parameters["@Param1"].Value = sParam1;
sda.SelectCommand = sqlCmd;
sda.Fill(ds);
}
finally
{
sqlConn.Close();
}
return ds;
I was getting the following error
"Request for the permission of type 'System.Data.SqlClient.SqlClientPermission, System.Data, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089' failed."
so I tried doing the following
SqlClientPermission pSql = new SqlClientPermission(System.Security.Permissions.PermissionState.Unrestricted);
pSql.Assert();
and then I get this error
"Request for the permission of type 'System.Security.Permissions.SecurityPermission, mscorlib, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089' failed."
Any idea how to remedy this ?
Thanks in advance
- Kan
View 4 Replies
View Related
Mar 25, 2007
I've been trying to build a data table that allows a client to add, edit and delete his itinerary. I've been using the products table in Northwind to get up to speed on this functions and everything works fine - (ie-connects to the database, shows the data I need, allows me to edit the data) but when I try to use the delete function, I keep getting the error below.
DELETE statement conflicted with COLUMN REFERENCE constraint 'FK_Order_Details_Products'. The conflict occurred in database 'Northwind', table 'Order Details', column 'ProductID'.The statement has been terminated.
Can anybody help me with this problem?
thanx
Code used is below:
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Gigs.aspx.cs" Inherits="Gigs" %>
<!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:SqlDataSource ID="SqlDataSource1" runat="server" ConnectionString="<%$ ConnectionStrings:NorthwindConnectionString %>"
DeleteCommand="DELETE FROM [Products] WHERE [ProductID] = @ProductID" InsertCommand="INSERT INTO [Products] ([ProductName], [SupplierID], [CategoryID], [QuantityPerUnit], [UnitPrice], [UnitsInStock], [UnitsOnOrder], [ReorderLevel], [Discontinued]) VALUES (@ProductName, @SupplierID, @CategoryID, @QuantityPerUnit, @UnitPrice, @UnitsInStock, @UnitsOnOrder, @ReorderLevel, @Discontinued)"
SelectCommand="SELECT * FROM [Products]" UpdateCommand="UPDATE [Products] SET [ProductName] = @ProductName, [SupplierID] = @SupplierID, [CategoryID] = @CategoryID, [QuantityPerUnit] = @QuantityPerUnit, [UnitPrice] = @UnitPrice, [UnitsInStock] = @UnitsInStock, [UnitsOnOrder] = @UnitsOnOrder, [ReorderLevel] = @ReorderLevel, [Discontinued] = @Discontinued WHERE [ProductID] = @ProductID">
<DeleteParameters>
<asp:Parameter Name="ProductID" Type="Int32" />
</DeleteParameters>
<UpdateParameters>
<asp:Parameter Name="ProductName" Type="String" />
<asp:Parameter Name="SupplierID" Type="Int32" />
<asp:Parameter Name="CategoryID" Type="Int32" />
<asp:Parameter Name="QuantityPerUnit" Type="String" />
<asp:Parameter Name="UnitPrice" Type="Decimal" />
<asp:Parameter Name="UnitsInStock" Type="Int16" />
<asp:Parameter Name="UnitsOnOrder" Type="Int16" />
<asp:Parameter Name="ReorderLevel" Type="Int16" />
<asp:Parameter Name="Discontinued" Type="Boolean" />
<asp:Parameter Name="ProductID" Type="Int32" />
</UpdateParameters>
<InsertParameters>
<asp:Parameter Name="ProductName" Type="String" />
<asp:Parameter Name="SupplierID" Type="Int32" />
<asp:Parameter Name="CategoryID" Type="Int32" />
<asp:Parameter Name="QuantityPerUnit" Type="String" />
<asp:Parameter Name="UnitPrice" Type="Decimal" />
<asp:Parameter Name="UnitsInStock" Type="Int16" />
<asp:Parameter Name="UnitsOnOrder" Type="Int16" />
<asp:Parameter Name="ReorderLevel" Type="Int16" />
<asp:Parameter Name="Discontinued" Type="Boolean" />
</InsertParameters>
</asp:SqlDataSource>
</div>
<asp:GridView ID="GridView1" runat="server" AllowPaging="True" AutoGenerateColumns="False"
CellPadding="4" DataKeyNames="ProductID" DataSourceID="SqlDataSource1" ForeColor="#333333"
GridLines="None">
<FooterStyle BackColor="#990000" Font-Bold="True" ForeColor="White" />
<Columns>
<asp:CommandField ShowDeleteButton="True" ShowEditButton="True" />
<asp:BoundField DataField="ProductID" HeaderText="ProductID" InsertVisible="False"
ReadOnly="True" SortExpression="ProductID" />
<asp:BoundField DataField="ProductName" HeaderText="ProductName" SortExpression="ProductName" />
<asp:BoundField DataField="SupplierID" HeaderText="SupplierID" SortExpression="SupplierID" />
<asp:BoundField DataField="CategoryID" HeaderText="CategoryID" SortExpression="CategoryID" />
<asp:BoundField DataField="QuantityPerUnit" HeaderText="QuantityPerUnit" SortExpression="QuantityPerUnit" />
<asp:BoundField DataField="UnitPrice" HeaderText="UnitPrice" SortExpression="UnitPrice" />
<asp:BoundField DataField="UnitsInStock" HeaderText="UnitsInStock" SortExpression="UnitsInStock" />
<asp:BoundField DataField="UnitsOnOrder" HeaderText="UnitsOnOrder" SortExpression="UnitsOnOrder" />
<asp:BoundField DataField="ReorderLevel" HeaderText="ReorderLevel" SortExpression="ReorderLevel" />
<asp:CheckBoxField DataField="Discontinued" HeaderText="Discontinued" SortExpression="Discontinued" />
</Columns>
<RowStyle BackColor="#FFFBD6" ForeColor="#333333" />
<SelectedRowStyle BackColor="#FFCC66" Font-Bold="True" ForeColor="Navy" />
<PagerStyle BackColor="#FFCC66" ForeColor="#333333" HorizontalAlign="Center" />
<HeaderStyle BackColor="#990000" Font-Bold="True" ForeColor="White" />
<AlternatingRowStyle BackColor="White" />
</asp:GridView>
</form>
</body>
</html>
aspx.cs code used below:
using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
public partial class Gigs : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
}
}
View 2 Replies
View Related
Jan 7, 2007
Here is the function I'm trying to write. The purpose is to replace MS Access Val() function. I'm not finished with the logic, I'm just trying to get this much to work now. Here is the function:create function DBO.NumValue
-- This function will get the numbers from the front of a field
-- and return the value of those numbers in a numeric data type
(@mNumInput as charvar(100))
RETURNSnumeric
AS
BEGIN
declare @x as tinyint
declare @x1 as tinyint
SET @x = 1
WHILE IsNumeric(SubString(@mNumInput, @x, 1))
BEGIN
SET @x1 = @x
SET @x = @x + 1
CONTINUE
END
If @x1 > 0
BEGIN
RETURN CAST(LEFT(@mNumInput, @x1), Numeric
END
END
Here are the two error messages I'm getting from this function.Server: Msg 156, Level 15, State 1, Procedure NumValue, Line 12
Incorrect syntax near the keyword 'BEGIN'.
Server: Msg 156, Level 15, State 1, Procedure NumValue, Line 20
Incorrect syntax near the keyword 'END'. I have no idea what these two error messages mean.
TIA,
View 7 Replies
View Related
Feb 22, 2006
I'm migrating from 2000 to 2005, what is the best way to handle the following error:
The ALL permission is deprecated and maintained only for compatibility. It DOES NOT imply ALL permissions defined on the entity
The code is below:
DECLARE @sp_name AS sysname;
DECLARE syscursor CURSOR FOR
SELECT name FROM sysobjects
WHERE (xtype = 'P' or xtype='V') AND ((status & 0x80000000) = 0);
OPEN syscursor;
FETCH NEXT FROM syscursor INTO @sp_name;
WHILE (@@FETCH_STATUS = 0)
BEGIN
EXECUTE ('GRANT all ON ' + @sp_name + ' TO Public');
FETCH NEXT FROM syscursor INTO @sp_name;
END
CLOSE syscursor;
DEALLOCATE syscursor;
View 5 Replies
View Related
Sep 6, 2006
Hi,
I'm new to this SQL thing, and I need some help with s stored procedure/function.
First, the scenario:
We are a social service agency, and like all such organizations, we have requirements for perodic reports about our clients. There are lots of them, but if I figure how to do one, I think I can apply the theory to the others.
First, this is some sample VBA code I've tested and which proved satisfactory for the basic task, just for a form. It is passed a date (dteDOP), then adds 3 months, (quarterly report)and loops until it exceeds the current date, thus generating the a due date for the the next report.
'initialize the due date
dteDueDate = dteDOP
'Add quarterly intervals, starting with (DOP + 3 months), until
'you exceed today's date
Do Until dteDueDate > Date
dteDueDate = DateAdd("m", 3, dteDueDate)
Loop
'set a text box to the next due date after today
Me.txtNextQuarDue = dteDueDate
Obviously, this isn't really a function at the moment, but it worked as a test of the logic, with instantly visible results.
This works, but I'd like to do it on the server end, so I can send out notifications. How would this be accomplished as an SQL stored procedure/function? Obviously, for that I'll need to again do a comparison of the current date with the due date for timing concerns, but that should be relatively simple. Also, I know that the '@' symbol is somehow part of variables in SQL Procedures/functions, could you give me a very basic explanation of this, especially the difference between @xxx and @@xxx?
Thanks in advance,
Stephen
-----------------------------------------------
-----------------------------------------------
Gary Getsum: What happened to my mule?
DM: It's dead; It got stung by a giant wasp.
Gary: Can't I heal it?
DM: I'm sorry, I know you were fond of the mule, but it just got attacked by a wasp the size of a Volkswagen!
Gary: So?
DM: Dude, look- you're going to have to carry all your own treasure now... Your mule gives new meaning to the term "Puff Daddy".
View 17 Replies
View Related
Apr 6, 2007
We are trying to create a TVF that executes a CLR Stored Procedure we wrote to use the results from the SP and transform them for the purposes of returning to the user as a table.
Code Snippet
[SqlFunction ( FillRowMethodName = "FillRow",
TableDefinition = "CustomerID nvarchar(MAX)",
SystemDataAccess = SystemDataAccessKind.Read,
DataAccess = DataAccessKind.Read,
IsDeterministic=false)]
public static IEnumerable GetWishlist () {
using (SqlConnection conn = new SqlConnection ( "Context Connection=true" )) {
List<string> myList = new List<string> ();
conn.Open ();
SqlCommand command = conn.CreateCommand ();
command.CommandText = "GetObject";
command.Parameters.AddWithValue ( "@map", "Item" );
command.CommandType = System.Data.CommandType.StoredProcedure;
using ( SqlDataReader reader = command.ExecuteReader ( System.Data.CommandBehavior.SingleRow )) {
if (reader.Read ()) {
myList.Add ( reader[0] as string );
}
}
return (IEnumerable)myList;
}
}
When command.ExecuteReader is called, I am getting an "Object not defined" error. However, the stored procedure can be used in SQL Management Studio just fine.
Code SnippetEXEC GetObject 'Item'
Is there some sorf of trick I am missing?
Thank you!
View 3 Replies
View Related
Apr 26, 2007
Hello, I am about out of hair from pulling it out. If someone could please show me what I'm doing wrong I would really appreciate it. I have this function for a SSRS 2005 report:
Public Function funAdditions(pFields As Fields) As Double
if pFields !FA00902_AMOUNT.Value > 0 and
pFields !FA00902_TRANSACCTTYPE.Value = 3 and
pFields !FA00902_DEPRTODATE.Value > Parameters!BeginDate.Value and
pFields !FA00902_DEPRTODATE.Value <= Parameters!CutOffDate.Value and NOT
instr(pFields !FA00902_SOURCDOC.Value, "FACHG")=1
then return pFields !FA00902_AMOUNT.Value
end
else if pFields !FA00902_TRANSACCTTYPE.Value = 3 and
pFields !FA00902_DEPRTODATE.Value > Parameters!BeginDate.Value and
pFields !FA00902_DEPRTODATE.Value <= Parameters!CutOffDate.Value and
instr(pFields !FA00902_SOURCDOC.Value, "FACHG")=1
then return pFields !FA00902_AMOUNT.Value
end
End Function
...and after much research cannot figure out the solution to this error:
[rsCompilerErrorInCode] There is an error on line 1 of custom code: [BC30201] Expression expected.
I'm new to SSRS so is there a syntax error I'm missing?
Thanks in advance,
Buster
View 1 Replies
View Related
Nov 23, 2015
I have a report that uses a stored procedure as a dataset.The stored procedure accepts four parameters, which I have defined in the report. works fine in query builder and SSMS.
When I run the report I get an error stating a parameter is missing. I tried deleting parameters and recreating not luck.
View 4 Replies
View Related
Sep 12, 2007
I put a function in the code section of Report Properties. I went to add an expression and can't find the function. I type =code. and did not see the function I created in the list.
Here's my code below:
Code Snippet
Public Function ConvertToStartDate(ByVal StartDate As String) As DateTime
Select Case StartDate
Case "Today"
Return DateTime.Today
Case "Yesterday"
Return DateTime.Today.AddDays(-1)
Case "30DaysOut"
Return DateTime.Today.AddDays(+30)
Case "2DaysPrior"
Return DateTime.Today.AddDays(-2)
' Additional cases
Case Else
Throw New ArgumentException("Unknown argument, " & StartDate, "StartDate")
End Select
End Function
I should be able to put in expression =code.ConvertToStartDate.StartDate("Today"), but that does not work. I get a red squiggly line under StartDate.
Thanks for your help,
Iris
View 3 Replies
View Related
Aug 9, 2006
I used a function to create dataset as below:
Public Function GetSQLDataSet(ByVal SQL As String) As DataSet
......
MyConnection = New SqlConnection(MyConnectionString)
MyCommand = New SqlCommand(SQL, MyConnection)
MyDataSet = New DataSet
MySQLDataAdapter = New SqlDataAdapter(MyCommand)
MySQLDataAdapter.Fill(MyDataSet)
......
End function
It works fine.
How to code a function to return a dataset in which there are two tables and relationship?
View 1 Replies
View Related
Nov 26, 2013
I have sql code that returns the correct number of record when run without an aggregate function like count(myfield) and group by myfield. It always returns 86 row which is correct when Select DISTINCT is used. As, expected when DISTINCT is not used I get double the number if rows or 172. But when I count(myfield) and group by myfield the count is 172 and not 86. The strangest thing about this is that when I am grouping a set of items
Group 1
Group 2
Group 3
The other group sum up correctly while others don't. What can explain this? Here is the code.
Select DISTINCT ws.p4Districtnumber, ws.cycle, ws.worksetid, count(msi.MeterSessionInputKey) as ASND
from fcs.dbo.WorkSet as ws
left outer join fcs.dbo.WorkAssignment as wa
on ws.WorkSetID = wa.WorkSetID
left outer join fcs.dbo.MeterSessionInput as msi
on wa.worksetkey = msi.worksetkey
[code]....
View 3 Replies
View Related
Aug 4, 2007
Hello,
I am trying to get this to work - but it only returns minutes & seconds:
Function Seconds2mmss(ByVal seconds As Integer) As String
Dim ss As Integer = seconds Mod 60
Dim mm As Integer = (seconds - ss) / 60
Seconds2mmss = String.Format("{0:0}:{1:00}", mm, ss)
End Function
Can anyone help me out? I am not that familiar with VB.
Thanks,
Deb
View 2 Replies
View Related
Aug 27, 2007
Now Sql Function can not modify data as Sql Procedure like other database, it's very troublesome at most case!
in most case, Sql Function is used to improve code structure then it can be maintanced easy! BUT only because it can not modify data, there are 2 troublesome way:
1. Make all callers in the path from Sql Functions to Sql Procedure. and the coder will cry, the code will become very
confusional , and very difficult to maintance.
2. Divide the Sql Function into a thin CLR wrapper to call a Sql Procedure, can only use another connection, BUT can not be in the same transaction context And the code is ugly and slow.
You should not give limitation to Sql Function, should just limit the using context of Sql Function!
The sql code is more difficult to read and maintance than norm code(C#), then the improving code structure and readability should be one of your most important task, that's why microsoft!
View 6 Replies
View Related
Jul 28, 2015
In the 70-461 objectives it says: Ensure code non regression by keeping consistent signature for procedure, views and function (interfaces); security implications...I think I understand what this means in general. They want us to be able to create a view that will still be able to call the original data even if the table is modified. In other words, the view table shouldn't easily be broken. ie, type a code that does NOT ensure non regression, then change the code so that it does ensure non regression.
View 4 Replies
View Related
Nov 3, 2015
How to encrypt the java application code using the 'with encryption' clause from sql server stored procedure or function.
View 3 Replies
View Related
Jul 1, 2015
I recently updated the datatype of a sproc parameter from bit to tinyint. When I executed the sproc with the updated parameters the sproc appeared to succeed and returned "1 row(s) affected" in the console. However, the update triggered by the sproc did not actually work.
The table column was a bit which only allows 0 or 1 and the sproc was passing a value of 2 so the table was rejecting this value. However, the sproc did not return an error and appeared to return success. So is there a way to configure the database or sproc to return an error message when this type of error occurs?
View 1 Replies
View Related
Jul 31, 2006
I have a parent package that calls child packages inside a For Each container. When I debug/run the parent package (from VS), I get the following error message: Warning: The Execution method succeeded, but the number of errors raised (3) reached the maximum allowed (1); resulting in failure. This occurs when the number of errors reaches the number specified in MaximumErrorCount. Change the MaximumErrorCount or fix the errors.
It appears to be failing while executing the child package. However, the logs (via the "progress" tab) for both the parent package and the child package show no errors other than the one listed above (and that shows in the parent package log). The child package appears to validate completely without error (all components are green and no error messages in the log). I turned on SSIS logging to a text file and see nothing in there either.
If I bump up the MaximumErrorCount in the parent package and in the Execute Package Task that calls the child package to 4 (to go one above the error count indicated in the message above), the whole thing executes sucessfully. I don't want to leave the Max Error Count set like this. Is there something I am missing? For example are there errors that do not get logged by default? I get some warnings, do a certain number of warnings equal an error?
Thanks,
Lee
View 5 Replies
View Related
Apr 20, 2006
Starwin writes "when i execute DBCC CHECKDB, DBCC CHECKCATALOG
I reveived the following error.
how to solve it?
Server: Msg 8909, Level 16, State 1, Line 1 Table error: Object ID -2093955965, index ID 711, page ID (3:2530). The PageId in the page header = (34443:343146507).
. . . .
. . . .
CHECKDB found 0 allocation errors and 1 consistency errors in table '(Object ID -1635188736)' (object ID -1635188736).
CHECKDB found 0 allocation errors and 1 consistency errors in table '(Object ID -1600811521)' (object ID -1600811521).
. . . .
. . . .
Server: Msg 8909, Level 16, State 1, Line 1 Table error: Object ID -8748568, index ID 50307, page ID (3:2497). The PageId in the page header = (26707:762626875).
Server: Msg 8909, Level 16, State 1, Line 1 Table error: Object ID -7615284, index ID 35836, page ID (3:2534). The PageId in the page heade"
View 1 Replies
View Related
Jul 27, 2006
Hi all--I'm trying to convert a function which I inherited from a SQL Server 2000 DTS package to something usable in an SSIS package in SQL Server 2005. Given the original code here:
Function Main()
on error resume next
dim cn, i, rs, sSQL
Set cn = CreateObject("ADODB.Connection")
cn.Open "Provider=sqloledb;Server=<server_name>;Database=<db_name>;User ID=<sysadmin_user>;Password=<password>"
set rs = CreateObject("ADODB.Recordset")
set rs = DTSGlobalVariables("SQLstring").value
for i = 1 to rs.RecordCount
sSQL = rs.Fields(0).value
cn.Execute sSQL, , 128 'adExecuteNoRecords option for faster execution
rs.MoveNext
Next
Main = DTSTaskExecResult_Success
End Function
This code was originally programmed in the SQL Server ActiveX Task type in a DTS package designed to take an open-ended number of SQL statements generated by another task as input, then execute each SQL statement sequentially. Upon this code's success, move on to the next step. (Of course, there was no additional documentation with this code. :-)
Based on other postings, I attempted to push this code into a Visual Studio BI 2005 Script Task with the following change:
public Sub Main()
...
Dts.TaskResult = Dts.Results.Success
End Class
I get the following error when I attempt to compile this:
Error 30209: Option Strict On requires all variable declarations to have an 'As' clause.
I am new to Visual Basic, so I'm on a learning curve here. From what I know of this script:
- The variables here violate the new Option Strict On requirement in VS 2005 to declare what type of object your variable is supposed to use.
- I need to explicitly declare each object, unless I turn off the Option Strict On (which didn't seem recommended, based on what I read).
Given this statement:
dim cn, i, rs, sSQL
I'm looking at "i" as type Integer; rs and sSQL are open-ended arrays, but can't quite figure out how to read the code here:
Set cn = CreateObject("ADODB.Connection")
cn.Open "Provider=sqloledb;Server=<server_name>;Database=<db_name>;User ID=<sysadmin_user>;Password=<password>"
set rs = CreateObject("ADODB.Recordset")
This code seems to create an instance of a COM component, then pass provider information and create the recordset being passed in by the previous task, but am not sure whether this syntax is correct for VS 2005 or what data type declaration to make here. Any ideas/help on how to rewrite this code would be greatly appreciated!
View 7 Replies
View Related
Mar 28, 2007
Dear Friends,
I am having 2 Tables.
Table 1: AddressBook
Fields --> User Name, Address, CountryCode
Table 2: Country
Fields --> Country Code, Country Name
Step 1 : I have created a Cube with these two tables using SSAS.
Step 2 : I have created a report in SSRS showing Address list.
The Column in the report are User Name, Address, Country Name
But I have no idea, how to convert this Country Code to Country name.
I am generating the report using the Layout tab. ( Data | Layout | Preview ) Report1.rdl [Design]
Anyone help me to solve this issue. Because, in our project most of the transaction tables have Code and Code description in master table. I need to convert all code into corresponding description in all my reports.
Thanks in advance.
Regards
Ramakrishnan
Singapore
28 March 2007
View 4 Replies
View Related
Feb 24, 2008
Hello,
I'm using ASP.Net to update a table which include a lot of fields may be around 30 fields, I used stored procedure to update these fields. Unfortunatily I had to use a FormView to handle some TextBoxes and RadioButtonLists which are about 30 web controls.
I 've built and tested my stored procedure, and it worked successfully thru the SQL Builder.The problem I faced that I have to define the variable in the stored procedure and define it again the code behind againALTER PROCEDURE dbo.UpdateItems
(
@eName nvarchar, @ePRN nvarchar, @cID nvarchar, @eCC nvarchar,@sDate nvarchar,@eLOC nvarchar, @eTEL nvarchar, @ePhone nvarchar,
@eMobile nvarchar, @q1 bit, @inMDDmn nvarchar, @inMDDyr nvarchar, @inMDDRetIns nvarchar,
@outMDDmn nvarchar, @outMDDyr nvarchar, @outMDDRetIns nvarchar, @insNo nvarchar,@q2 bit, @qper2 nvarchar, @qplc2 nvarchar, @q3 bit, @qper3 nvarchar, @qplc3 nvarchar,
@q4 bit, @qper4 nvarchar, @pic1 nvarchar, @pic2 nvarchar, @pic3 nvarchar, @esigdt nvarchar, @CCHName nvarchar, @CCHTitle nvarchar, @CCHsigdt nvarchar, @username nvarchar,
@levent nvarchar, @eventdate nvarchar, @eventtime nvarchar
)
AS
UPDATE iTrnsSET eName = @eName, cID = @cID, eCC = @eCC, sDate = @sDate, eLOC = @eLOC, eTel = @eTEL, ePhone = @ePhone, eMobile = @eMobile,
q1 = @q1, inMDDmn = @inMDDmn, inMDDyr = @inMDDyr, inMDDRetIns = @inMDDRetIns, outMDDmn = @outMDDmn,
outMDDyr = @outMDDyr, outMDDRetIns = @outMDDRetIns, insNo = @insNo, q2 = @q2, qper2 = @qper2, qplc2 = @qplc2, q3 = @q3, qper3 = @qper3,
qplc3 = @qplc3, q4 = @q4, qper4 = @qper4, pic1 = @pic1, pic2 = @pic2, pic3 = @pic3, esigdt = @esigdt, CCHName = @CCHName,
CCHTitle = @CCHTitle, CCHsigdt = @CCHsigdt, username = @username, levent = @levent, eventdate = @eventdate, eventtime = @eventtime
WHERE (ePRN = @ePRN)
and the code behind which i have to write will be something like thiscmd.CommandType = CommandType.StoredProcedure;
cmd.Parameters.AddWithValue("@eName", ((TextBox)FormView1.FindControl("TextBox1")).Text);cmd.Parameters.AddWithValue("@ePRN", ((TextBox)FormView1.FindControl("TextBox2")).Text);
cmd.Parameters.AddWithValue("@cID", ((TextBox)FormView1.FindControl("TextBox3")).Text);cmd.Parameters.AddWithValue("@eCC", ((TextBox)FormView1.FindControl("TextBox4")).Text);
((TextBox)FormView1.FindControl("TextBox7")).Text = ((TextBox)FormView1.FindControl("TextBox7")).Text + ((TextBox)FormView1.FindControl("TextBox6")).Text + ((TextBox)FormView1.FindControl("TextBox5")).Text;cmd.Parameters.AddWithValue("@sDate", ((TextBox)FormView1.FindControl("TextBox7")).Text);
cmd.Parameters.AddWithValue("@eLOC", ((TextBox)FormView1.FindControl("TextBox8")).Text);cmd.Parameters.AddWithValue("@eTel", ((TextBox)FormView1.FindControl("TextBox9")).Text);
cmd.Parameters.AddWithValue("@ePhone", ((TextBox)FormView1.FindControl("TextBox10")).Text);
cmd.Parameters.AddWithValue("@eMobile", ((TextBox)FormView1.FindControl("TextBox11")).Text);
So is there any way to do it better than this way ??
Thank you
View 2 Replies
View Related
Oct 16, 2007
Hi all,
Could someone tell me if custom code function can capture the event caused by a user? For example, onclick event on the rendered report?
Also, can custom code function alter the parameters of the report, or refresh the report?
Thanks.
View 2 Replies
View Related
Jan 25, 2007
Hi,I need some help here. I have a SELECT sql statement that will query the table. How do I get the return value from the sql statement to be assigned to a label. Any article talk about this? Thanks geniuses.
View 2 Replies
View Related
Aug 1, 2005
I have this function in access I need to be able to use in ms sql. Having problems trying to get it to work. The function gets rid of the leading zeros if the field being past dosn't have any non number characters.For example:TrimZero("000000001023") > "1023"TrimZero("E1025") > "E1025"TrimZero("000000021021") > "21021"TrimZero("R5545") > "R5545"Here is the function that works in access:Public Function TrimZero(strField As Variant) As String Dim strReturn As String If IsNull(strField) = True Then strReturn = "" Else strReturn = strField Do While Left(strReturn, 1) = "0" strReturn = Mid(strReturn, 2) Loop End If TrimZero = strReturnEnd Function
View 3 Replies
View Related