Variable Assignment

Apr 7, 2008

Is it possible to set the value for several variables from one select query?

View 4 Replies


ADVERTISEMENT

Variable Assignment

Jul 21, 1999

How do you assign the value returned by a stored procedure to a declared variable and then display the value of that declared variable?

The following does not work:

declare @variable int
set @variable = stored_procedure
...
...
show value of @variable?? <HOW>

Sorry for the stupid questions but I am new to SQL in general.

View 1 Replies View Related

Variable Assignment

Apr 7, 2008

Is it possible to set the value for several variables from one select query?

View 1 Replies View Related

Inline Variable Assignment

Jan 22, 2004

I have to write a query for printing multiple barcodes, depending on the quantity of items that came in the store, based on the order number.



DECLARE @num INT
SELECT BarCodes.BarCode, BarCodes.ArticleID, ArticlesTrafic.DocumentID, ArticlesTrafic.TrafficQuantity
FROM BarCodes INNER JOIN
Articles ON BarCodes.ArticleID = Articles.ArticleID INNER JOIN
getAutoNumberTable(@num) ON @num=ArticlesTrafic.TrafficQuantity
WHERE (ArticlesTrafic.DocumentID = @Param2)



The thing i would like to do, is somehow assign a value to @num and pass it to the getAutoNumberTable stored procedure, which generates a table of consequtive numbers, so that each record is displayed multiple times. Is it even possible to do it without using temp tables and loops?

View 1 Replies View Related

Variable Assignment In Cursor Declaration

Jul 5, 2006

Hi,

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

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

thanks

View 8 Replies View Related

Local Variable Assignment In CREATE TRIGGER

Mar 7, 2006

Hi Guys,

i'm batttling with the below Trigger creation

__________________________________________________ _
CREATE TRIGGER dbo.Fochini_Insert ON dbo.FochiniTable AFTER INSERT AS
BEGIN
DECLARE @v_object_key VARCHAR(80)
DECLARE @v_object_name VARCHAR(40)
DECLARE @v_object_verb VARCHAR(40)
DECLARE @v_datetime DATETIME

SELECT ins.Cust_Id INTO @v_object_key FROM inserted ins <--- my problem area!!
SET @v_object_name = 'FochiniTable'
SET @v_object_verb = 'Create'
SET @v_datetime = GETDATE()

IF ( USER <> 'webuser' )
INSERT INTO dbo.xworlds_events (connector_id, object_key, object_name, object_verb, event_priority, event_time, event_status, event_comment)
VALUES ('Fochini', @v_object_key, @v_object_name, @v_object_verb, '1', @v_datetime,'0', 'Triggered by Customer CREATE')

END
________________________________________________

i'm trying to get the INSERTED variable from table FochiniTable on colomn Cust_Id

and the statement: SELECT ins.Cust_Id INTO @v_object_key FROM inserted ins - is failing [still a newbie on mssql server 2000]

any help will be appreciated
lehare.

View 1 Replies View Related

Help On Script Component Assignment Of Output Variable

Sep 7, 2005

Hi all,

View 9 Replies View Related

Parent Package Variable Assignment Issue In Child Package.

Dec 26, 2006


We
have one main package from which 7 other child packages are called. We are using
ParentPackage variables to assign values for variables and database connections.



While the values from ParentPackage variable get assigned to some of the
packages properly, to others it doesn€™t assign the value.

For example:
Except for one of the packages the database connection string gets assigned
properly to all other packages.

Similarly, in another package one of the
variables doesn€™t get assigned. In other packages it is assigned properly.

We
have checked all the other property values and they are exactly the same.


We cannot make any head or tail of this erratic behavior.

Please Help.

View 3 Replies View Related

Need Urgent Help In Assignment Please!!

Apr 15, 2004

I want to know the answer of this question please as i have to submit my assignment as soon as possible. The assignmet question is" We use Composite Index on a table. Which of the following statements will speed up and slow down the operations respectively:
1-Select 2-Insert 3-Modify 4-Delete "

So is there anyone who can help me in this? i would appreciate that! :)

Thanks

View 4 Replies View Related

Need Help With SQL Server Assignment!

Dec 6, 2007

Hi everyone. This is my first time here, and I am really in need of some help! I am a senior Information Technology Major and I am in my first SQL course where I have to write a report on a company that uses SQL Server. I haven't been able to find any companies in my area, and need to find a company to write my paper on as soon as possible. I just have a set of brief questions; they are as follows (and I understand, for security reasons, if you are unable to answer certain questions, do not feel obligated to do so!):

Basics:
A brief overview of your company:
What is your position?
What the SQL Server database is used for?

Implementation:
Which version of MS SQL Server is used?
Type of instance(s) is(are) used?
Which authentication mode is used?
Do you utilize SQL Server Dynamic Disk Space Management, and if so, how?
How is data security maintained?
What type of encryption has been implemented?

Maintenance:
What type of backups are completed and how often?
How would the database would be restored in the event of data loss?
How do you preserve data integrity within the database?
Do you utilize any monitoring & troubleshooting tools to assess SQL Server performance (SQL Server Profiler, System Monitor, Database Engine Tuning Advisor, etc).

I greatly appreciate anyone willing to help me with my paper. Thank you!
Lynette

View 2 Replies View Related

Dynamic Database Assignment???

Jan 25, 2001

I have an application that is developed to support a customer per database. All the data is unique to that customer and is physically partitioned from other customers. Also, I have a database that has common tables to all customers. I use stored procedures to access all data. I would like to keep from duplicating all the stored procedures (since the meat of them stays the same) because of the database references.

Is there any way to use the "USE <database>" functionality in the stored procedures to switch context dynamically without having to reference the unique databases?

Thank You,
Brian

View 4 Replies View Related

Parameter Assignment In DTS SQL Task

Sep 13, 2006

Greetings and salutations brilliant people!

I have a problem that I can't find any information on and I bet someone here has hit the wall on this.

I have 2 sql server 2000 servers runnng sql std edition. One has 8.00.2039 SP4 and one has 8.00.818 SP3. The server with SP4 will not let me use a parameter in the DTS SQL task. I get the infamous Access Violation Error. If I replicate the SQL task on the SP3 server I have no problem works great and life is good.

Can anyone tell me if thre is a hotfix for this or something? I've googled this to death and tried various possible fixes with no positive result. Any help would be greatly appreciated!!

Thanks for viewing! :)

View 2 Replies View Related

Assignment Question, Hit Road Block.

Mar 14, 2008

I am new to sql.
Question1: How do i run a CHECK against serveral words.
e.g. check("name" is either bill or timmy or sally or jessy)

Question2: What is the best variable to use for time.

View 4 Replies View Related

Reporting Services: Role Assignment Without Using Report Manager

Jul 20, 2005

Hello,I'm having some problems using the Report Manager, but I *really* needto make a role assignment now. Can't wait to have the problem withReport Manager solved.So, I would like to make this role assignment directly in theReportServer database, using the SP SetPolicy or some other SP.I'm looking for the equivalent of making the "New Role Assignment" andthenGroup or user name: EveryoneRole "Browser" checkedOKCan anyone tell me exactly how to do this?Thanks in advance,Filipe HenriquesPS: By the way, the problem I've got using the Report Manager is thatalways appear "The request failed with HTTP status 404: Not Found.",although I can see perfectly the Report Server page.Does anyone knows what's the problem?

View 3 Replies View Related

There Is Nothing Happen After Click Finish Checkout On My Shopping Cart Assignment

Mar 16, 2008

Hi all,
There is nothing happen when I finished my checkout process, I expect the data will be saved to order and orderitem table in my SQL database, but no data found on order and orderitem table and no error messages display during operation!!!
Below is my checkout.aspx.vb code, the whole code line number around 138, I captured the part from 1~ 64 line number, I suspect line 35 - 48 have a problem, can somebody help me, many thanks.
 1 Imports System
2 Imports System.Data.SqlClient
3 Imports SW.Commerce
4 Partial Class CheckOut
5 Inherits System.Web.UI.Page
6 Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
7 If Not Page.IsPostBack Then
8 If Profile.Cart Is Nothing Then
9 NoCartlabel.Visible = True
10 Wizard1.Visible = False
11 End If
12 If User.Identity.IsAuthenticated Then
13 Wizard1.ActiveStepIndex = 1
14 Else
15 Wizard1.ActiveStepIndex = 0
16 End If
17 End If
18 End Sub
19 Sub chkUseProfileAddress_CheckedChanged(ByVal sender As Object, ByVal e As System.EventArgs)
20
21 ' fill the delivery address from the profile, but only if it’s empty
22 ' we don’t want to overwrite the values
23
24 If chkUseProfileAddress.Checked AndAlso txtName.Text.Trim() = "" Then
25 txtName.Text = Profile.Name
26 txtAddress.Text = Profile.Address
27 txtcity.Text = Profile.City
28 txtCountry.Text = Profile.Country
29 End If
30 End Sub
31 Sub Wizard1_FinishButtonClick(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.WizardNavigationEventArgs)
32
33 ' Insert the order and order lines into the database
34
35 Dim conn As SqlConnection = Nothing
36 Dim trans As SqlTransaction = Nothing
37 Dim cmd As SqlCommand
38 Try
39 conn = New SqlConnection(ConfigurationManager.ConnectionStrings("swshop").connectionstring)
40 conn.Open()
41 trans = conn.BeginTransaction
42 cmd = New SqlCommand()
43 cmd.Connection = conn
44 cmd.Transaction = trans
45
46 ' set the order details
47
48 cmd.CommandText = "INSERT INTO Order(MemberName, OrderDate, Name, Address1, Address2, Country, Total) VALUES (@MemberName, @OrderDate, @Name, @Address, @city, @Country, @Total)"
49 cmd.Parameters.Add("@MemberName", Data.SqlDbType.VarChar, 50)
50 cmd.Parameters.Add("@OrderDate", Data.SqlDbType.DateTime)
51 cmd.Parameters.Add("@Name", Data.SqlDbType.VarChar, 50)
52 cmd.Parameters.Add("@Address", Data.SqlDbType.VarChar, 255)
53 cmd.Parameters.Add("@City", Data.SqlDbType.VarChar, 15)
54 cmd.Parameters.Add("@Country", Data.SqlDbType.VarChar, 50)
55 cmd.Parameters.Add("@Total", Data.SqlDbType.Money)
56 cmd.Parameters("@MemberName").Value = User.Identity.Name
57 cmd.Parameters("@OrderDate").Value = DateTime.Now()
58 cmd.Parameters("@Name").Value = CType(Wizard1.FindControl("txtName"), TextBox).Text
59 cmd.Parameters("@Address").Value = CType(Wizard1.FindControl("txtAddress"), TextBox).Text
60 cmd.Parameters("@City").Value = CType(Wizard1.FindControl("txtCity"), TextBox).Text
61 cmd.Parameters("@Country").Value = CType(Wizard1.FindControl("txtCountry"), TextBox).Text
62 cmd.Parameters("@Total").Value = Profile.Cart.Total
63 Dim OrderID As Integer
64 OrderID = Convert.ToInt32(cmd.ExecuteScalar())

 Below is checkout.aspx1 <%@ Import Namespace ="System.Data.SqlClient"%>
2 <%@ Import Namespace ="SW.Commerce"%>
3 <%@ Page Language="VB" MasterPageFile="~/SWSHOP.master" AutoEventWireup="false" CodeFile="CheckOut.aspx.vb" Inherits="CheckOut" title="Untitled Page" %>
4
5 <%@ Register Src="SWShoppingCart.ascx" TagName="SWShoppingCart" TagPrefix="uc1" %>
6 <asp:Content ID="Content1" ContentPlaceHolderID="ContentPlaceHolder1" Runat="Server">
7
8 <asp:Label id="NoCartlabel" runat="server" visible="false">
9 There are no items in your cart. Visit the shop to buy items.
10 </asp:Label>
11
12 <div style="float:right">
13  </div>
14
15
16 <asp:Wizard ID="Wizard1" runat="server" ActiveStepIndex="1" Width="274px">
17 <WizardSteps>
18 <asp:WizardStep runat="server" Title="Login">
19 <asp:Login ID="Login1" runat="server">
20 </asp:Login>
21 </asp:WizardStep>
22 <asp:WizardStep runat="server" Title="Delievery Address">
23 <asp:checkbox id="chkUseProfileAddress" runat="server" autopostback="True"
24 text="Use membership address"
25 OnCheckedChanged="chkUseProfileAddress_CheckedChanged"></asp:checkbox><br />
26 <table border=�0�>
27 <tr><td>Name</td><td><asp:textbox id="txtName" runat="server" /></td></tr>
28 <tr><td>Address</td><td><asp:textbox id="txtAddress" runat="server" /></td></tr>
29 <tr><td>City</td><td><asp:textbox id="txtcity" runat="server" /></td></tr>
30 <tr><td>
31 Country</td><td><asp:textbox id="txtCountry" runat="server" /></td></tr>
32 </table>
33 </asp:WizardStep>
34 <asp:WizardStep runat="server" Title="Payment">
35 <asp:DropDownList id="lstCardType" runat="server">
36 <asp:ListItem>MasterCard</asp:ListItem>
37 <asp:ListItem>Visa</asp:ListItem>
38 </asp:DropDownList>
39 <br />
40 Card Number: <asp:Textbox id="txtNumber" runat="server" Text="0123456789" ReadOnly="True"/>
41 <br />
42 Expires: <asp:textbox id="txtExpiresMonth" runat="server" columns="2" />
43 /
44 <asp:textbox id="txtExpiresYear" runat="server" columns="4" />
45 </asp:WizardStep>
46 <asp:WizardStep runat="server" Title="confirmation">
47 <uc1:SWShoppingCart ID="SWShoppingCart1" runat="server" />
48 <br />
49 <br />
50 Please confirm amount you wish to have deduct from your credit card.
51 </asp:WizardStep>
52 <asp:WizardStep runat="server" Title="Complete">
53 Thank you for your order.</asp:WizardStep>
54 </WizardSteps>
55 </asp:Wizard>
56 </asp:Content>
57 <asp:Content ID="Content2" ContentPlaceHolderID="ContentPlaceHolder3" Runat="Server">
58 <asp:LoginView ID="LoginView1" Runat="server">
59 <AnonymousTemplate>
60 <asp:passwordrecovery id="PasswordRecovery1" runat="server" />
61 </AnonymousTemplate>
62 </asp:LoginView>
63 </asp:Content>
 

View 2 Replies View Related

Error 409: The Assignment Operator Operation Could Not Take A Text Data Type As An Argument

Aug 2, 2004

How can I make it work when I need to pull out a field which is text type using a stored procedure? Please help!!!Thanks
I am getting the following error
Error 409: The assignment operator operation could not take a text data type as an argument
===========my sp=================================
CREATE PROCEDURE [dbo].[sp_SelectABC]
(@a varchar(50) output,
@b text output
)
AS
set nocount on
select @a=name, @b= description from ABC

GO

View 1 Replies View Related

SSIS Script Task Alters Package Variable, But Variable Does Not Change.

Oct 25, 2006

I'm working on an SSIS package that uses a vb.net script to grab some XML from a webservice (I'd explain why I'm not using a web service task here, but I'd just get angry), and I wish to then assign the XML string to a package variable which then gets sent along to a DataFlow Task that contains an XML Source that points at said variable. when I copy the XML string into the variable value in the script, if do a quickwatch on the variable (as in Dts.Variable("MyXML").value) it looks as though the new value has been copied to the variable, but when I step out of that task and look at the package explorer the variable is its original value.

I think the problem is that the dataflow XML source has a lock on the variable and so the script task isn't affecting it. Does anyone have any experience with this kind of problem, or know a workaround?

View 1 Replies View Related

Passing A SSIS Global Variable To A Declared Variable In A Query In SQL Task

Mar 6, 2008

I have a SQL Task that updates running totals on a record inserted using a Data Flow Task. The package runs without error, but the actual row does not calculate the running totals. I suspect that the inserted record is not committed until the package completes and the SQL Task is seeing the previous record as the current. Here is the code in the SQL Task:

DECLARE @DV INT;
SET @DV = (SELECT MAX(DateValue) FROM tblTG);
DECLARE @PV INT;
SET @PV = @DV - 1;

I've not been successful in passing a SSIS global variable to a declared parameter, but is it possible to do this:

DECLARE @DV INT;
SET @DV = ?;
DECLARE @PV INT;
SET @PV = @DV - 1;


I have almost 50 references to these parameters in the query so a substitution would be helpful.

Dan

View 4 Replies View Related

SSIS: Problem Mapping Global Variables To Stored Procedure. Can't Pass One Variable To Sp And Return Another Variable From Sp.

Feb 27, 2008

I'm new to SSIS, but have been programming in SQL and ASP.Net for several years. In Visual Studio 2005 Team Edition I've created an SSIS that imports data from a flat file into the database. The original process worked, but did not check the creation date of the import file. I've been asked to add logic that will check that date and verify that it's more recent than a value stored in the database before the import process executes.

Here are the task steps.


[Execute SQL Task] - Run a stored procedure that checks to see if the import is running. If so, stop execution. Otherwise, proceed to the next step.

[Execute SQL Task] - Log an entry to a table indicating that the import has started.

[Script Task] - Get the create date for the current flat file via the reference provided in the file connection manager. Assign that date to a global value (FileCreateDate) and pass it to the next step. This works.

[Execute SQL Task] - Compare this file date with the last file create date in the database. This is where the process breaks. This step depends on 2 variables defined at a global level. The first is FileCreateDate, which gets set in step 3. The second is a global variable named IsNewFile. That variable needs to be set in this step based on what the stored procedure this step calls finds out on the database. Precedence constraints direct behavior to the next proper node according to the TRUE/FALSE setting of IsNewFile.


If IsNewFile is FALSE, direct the process to a step that enters a log entry to a table and conclude execution of the SSIS.

If IsNewFile is TRUE, proceed with the import. There are 5 other subsequent steps that follow this decision, but since those work they are not relevant to this post.
Here is the stored procedure that Step 4 is calling. You can see that I experimented with using and not using the OUTPUT option. I really don't care if it returns the value as an OUTPUT or as a field in a recordset. All I care about is getting that value back from the stored procedure so this node in the decision tree can point the flow in the correct direction.


CREATE PROCEDURE [dbo].[p_CheckImportFileCreateDate]

/*

The SSIS package passes the FileCreateDate parameter to this procedure, which then compares that parameter with the date saved in tbl_ImportFileCreateDate.

If the date is newer (or if there is no date), it updates the field in that table and returns a TRUE IsNewFile bit value in a recordset.

Otherwise it returns a FALSE value in the IsNewFile column.

Example:

exec p_CheckImportFileCreateDate 'GL Account Import', '2/27/2008 9:24 AM', 0

*/

@ProcessName varchar(50)

, @FileCreateDate datetime

, @IsNewFile bit OUTPUT

AS

SET NOCOUNT ON

--DECLARE @IsNewFile bit

DECLARE @CreateDateInTable datetime

SELECT @CreateDateInTable = FileCreateDate FROM tbl_ImportFileCreateDate WHERE ProcessName = @ProcessName

IF EXISTS (SELECT ProcessName FROM tbl_ImportFileCreateDate WHERE ProcessName = @ProcessName)

BEGIN

-- The process exists in tbl_ImportFileCreateDate. Compare the create dates.

IF (@FileCreateDate > @CreateDateInTable)

BEGIN

-- This is a newer file date. Update the table and set @IsNewFile to TRUE.

UPDATE tbl_ImportFileCreateDate

SET FileCreateDate = @FileCreateDate

WHERE ProcessName = @ProcessName

SET @IsNewFile = 1

END

ELSE

BEGIN

-- The file date is the same or older.

SET @IsNewFile = 0

END

END

ELSE

BEGIN

-- This is a new process for tbl_ImportFileCreateDate. Add a record to that table and set @IsNewFile to TRUE.

INSERT INTO tbl_ImportFileCreateDate (ProcessName, FileCreateDate)

VALUES (@ProcessName, @FileCreateDate)

SET @IsNewFile = 1

END

SELECT @IsNewFile

The relevant Global Variables in the package are defined as follows:
Name : Scope : Date Type : Value
FileCreateDate : (Package Name) : DateType : 1/1/2000
IsNewFile : (Package Name) : Boolean : False

Setting the properties in the "Execute SQL Task Editor" has been the difficult part of this. Here are the settings.

General
Name = Compare Last File Create Date
Description = Compares the create date of the current file with a value in tbl_ImportFileCreateDate.
TimeOut = 0
CodePage = 1252
ResultSet = None
ConnectionType = OLE DB
Connection = MyServerDataBase
SQLSourceType = Direct input
IsQueryStoredProcedure = False
BypassPrepare = True

I tried several SQL statements, suspecting it's a syntax issue. All of these failed, but with different error messages. These are the 2 most recent attempts based on posts I was able to locate.
SQLStatement = exec ? = dbo.p_CheckImportFileCreateDate 'GL Account Import', ?, ? output
SQLStatement = exec p_CheckImportFileCreateDate 'GL Account Import', ?, ? output

Parameter Mapping
Variable Name = User::FileCreateDate, Direction = Input, DataType = DATE, Parameter Name = 0, Parameter Size = -1
Variable Name = User::IsNewFile, Direction = Output, DataType = BYTE, Parameter Name = 1, Parameter Size = -1

Result Set is empty.
Expressions is empty.

When I run this in debug mode with this SQL statement ...
exec ? = dbo.p_CheckImportFileCreateDate 'GL Account Import', ?, ? output
... the following error message appears.

SSIS package "MyPackage.dtsx" starting.
Information: 0x4004300A at Import data from flat file to tbl_GLImport, DTS.Pipeline: Validation phase is beginning.

Error: 0xC002F210 at Compare Last File Create Date, Execute SQL Task: Executing the query "exec ? = dbo.p_CheckImportFileCreateDate 'GL Account Import', ?, ? output" failed with the following error: "No value given for one or more required parameters.". Possible failure reasons: Problems with the query, "ResultSet" property not set correctly, parameters not set correctly, or connection not established correctly.

Task failed: Compare Last File Create Date

Warning: 0x80019002 at GLImport: SSIS Warning Code DTS_W_MAXIMUMERRORCOUNTREACHED. The Execution method succeeded, but the number of errors raised (1) 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.

SSIS package "MyPackage.dtsx" finished: Failure.

When the above is run tbl_ImportFileCreateDate does not get updated, so it's failing at some point when calling the procedure.

When I run this in debug mode with this SQL statement ...
exec p_CheckImportFileCreateDate 'GL Account Import', ?, ? output
... the tbl_ImportFileCreateDate table gets updated. So I know that data piece is working, but then it fails with the following message.

SSIS package "MyPackage.dtsx" starting.
Information: 0x4004300A at Import data from flat file to tbl_GLImport, DTS.Pipeline: Validation phase is beginning.

Error: 0xC001F009 at GLImport: The type of the value being assigned to variable "User::IsNewFile" differs from the current variable type. Variables may not change type during execution. Variable types are strict, except for variables of type Object.

Error: 0xC002F210 at Compare Last File Create Date, Execute SQL Task: Executing the query "exec p_CheckImportFileCreateDate 'GL Account Import', ?, ? output" failed with the following error: "The type of the value being assigned to variable "User::IsNewFile" differs from the current variable type. Variables may not change type during execution. Variable types are strict, except for variables of type Object.
". Possible failure reasons: Problems with the query, "ResultSet" property not set correctly, parameters not set correctly, or connection not established correctly.
Task failed: Compare Last File Create Date

Warning: 0x80019002 at GLImport: SSIS Warning Code DTS_W_MAXIMUMERRORCOUNTREACHED. 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.

SSIS package "MyPackage.dtsx" finished: Failure.

The IsNewFile global variable is scoped at the package level and has a Boolean data type, and the Output parameter in the stored procedure is defined as a Bit. So what gives?

The "Possible Failure Reasons" message is so generic that it's been useless to me. And I've been unable to find any examples online that explain how to do what I'm attempting. This would seem to be a very common task. My suspicion is that one or more of the settings in that Execute SQL Task node is bad. Or that there is some cryptic, undocumented reason that this is failing.

Thanks for your help.

View 5 Replies View Related

Compare The Value Of A Variable With Previous Variable From A Function ,reset The Counter When Val Changes

Oct 15, 2007

I am in the middle of taking course 2073B €“ Programming a Microsoft SQL Server 2000 Database. I noticed that in Module9: Implementing User-Defined Functions exercise 2, page 25; step 2 is not returning the correct answer.

Select employeeid,name,title,mgremployeeid from dbo.fn_findreports(2)

It returns manager id for both 2 and 5 and I think it should just return the results only for manager id 2. The query results for step 1 is correct but not for step 2.

Somewhere in the code I think it should compare the inemployeeid with the previous inemployeeid, and then add a counter. If the two inemployeeid are not the same then reset the counter. Then maybe add an if statement or a case statement. Can you help with the logic? Thanks!

Here is the code of the function in the book:

/*
** fn_FindReports.sql
**
** This multi-statement table-valued user-defined
** function takes an EmplyeeID number as its parameter
** and provides information about all employees who
** report to that person.
*/
USE ClassNorthwind
GO
/*
** As a multi-statement table-valued user-defined
** function it starts with the function name,
** input parameter definition and defines the output
** table.
*/
CREATE FUNCTION fn_FindReports (@InEmployeeID char(5))
RETURNS @reports TABLE
(EmployeeID char(5) PRIMARY KEY,
Name nvarchar(40) NOT NULL,
Title nvarchar(30),
MgrEmployeeID int,
processed tinyint default 0)
-- Returns a result set that lists all the employees who
-- report to a given employee directly or indirectly
AS
BEGIN
DECLARE @RowsAdded int
-- Initialize @reports with direct reports of the given employee
INSERT @reports
SELECT EmployeeID, Name = FirstName + ' ' + LastName, Title, ReportsTo, 0
FROM EMPLOYEES
WHERE ReportsTo = @InEmployeeID
SET @RowsAdded = @@rowcount
-- While new employees were added in the previous iteration
WHILE @RowsAdded > 0
BEGIN
-- Mark all employee records whose direct reports are going to be
-- found in this iteration
UPDATE @reports
SET processed = 1
WHERE processed = 0

-- Insert employees who report to employees marked 1
INSERT @reports
SELECT e.EmployeeID, Name = FirstName + ' ' + LastName , e.Title, e.ReportsTo, 0
FROM employees e, @reports r
WHERE e.ReportsTo = r.EmployeeID
AND r.processed = 1
SET @RowsAdded = @@rowcount
-- Mark all employee records whose direct reports have been
-- found in this iteration
UPDATE @reports
SET processed = 2
WHERE processed = 1
END
RETURN -- Provides the value of @reports as the result
END
GO

View 1 Replies View Related

Scripting: Dumb Q.. How Can I Store A DTS Variable Inside A Script Variable?

Nov 1, 2005

Hi

View 7 Replies View Related

Debug Error - Object Variable Or With Block Variable Not Set -

Feb 15, 2006

I keep getting this debug error, see my code below, I have gone thru it time and time agian and do not see where the problem is.  I have checked and have no  NULL values that I'm trying to write back.
~~~~~~~~~~~
Error:
System.NullReferenceException was unhandled by user code  Message="Object variable or With block variable not set."  Source="Microsoft.VisualBasic"
~~~~~~~~~~~~
My Code
Dim DBConn As SqlConnection
Dim DBAdd As New SqlCommand
Dim strConnect As String = ConfigurationManager.ConnectionStrings("ProtoCostConnectionString").ConnectionString
DBConn = New SqlConnection(strConnect)
DBAdd.CommandText = "INSERT INTO D12_MIS (" _
& "CSJ, EST_DATE, RECORD_LOCK_FLAG, EST_CREATE_BY_NAME, EST_REVIEW_BY_NAME, m2_1, m2_2_date, m2_3_date, m2_4_date, m2_5, m3_1a, m3_1b, m3_2a, m3_2b, m3_3a, m3_3b" _
& ") values (" _
& "'" & Replace(vbCSJ.Text, "'", "''") _
& "', " _
& "'" & Replace(tmp1Date, "'", "''") _
& "', " _
& "'" & Replace(tmpRecordLock, "'", "''") _
& "', " _
& "'" & Replace(CheckedCreator, "'", "''") _
& "', " _
& "'" & Replace(CheckedReviewer, "'", "''") _
& "', " _
& "'" & Replace(vb2_1, "'", "''") _
& "', " _
& "'" & Replace(tmp2Date, "'", "''") _
& "', " _
& "'" & Replace(tmp3Date, "'", "''") _
& "', " _
& "'" & Replace(tmp4Date, "'", "''") _
& "', " _
& "'" & Replace(vb2_5, "'", "''") _
& "', " _
& "'" & Replace(vb3_1a, "'", "''") _
& "', " _
& "'" & Replace(vb3_1b, "'", "''") _
& "', " _
& "'" & Replace(vb3_2a, "'", "''") _
& "', " _
& "'" & Replace(vb3_2b, "'", "''") _
& "', " _
& "'" & Replace(vb3_3a, "'", "''") _
& "', " _
& "'" & Replace(vb3_3b, "'", "''") _
& "')"
DBAdd.Connection = DBConn
DBAdd.Connection.Open()
DBAdd.ExecuteNonQuery()
DBAdd.Connection.Close()

View 2 Replies View Related

Transact SQL :: Insert Values From Variable Into Table Variable

Nov 4, 2015

CREATE TABLE #T(branchnumber VARCHAR(4000))

insert into #t(branchnumber) values (005)
insert into #t(branchnumber) values (090)
insert into #t(branchnumber) values (115)
insert into #t(branchnumber) values (210)
insert into #t(branchnumber) values (216)

[code]....

I have a parameter which should take multiple values into it and pass that to the code that i use. For, this i created a parameter and temporarily for testing i am passing some values into it.Using a dynamic SQL i am converting multiple values into multiple records as rows into another variable (called @QUERY). My question is, how to insert the values from variable into a table (table variable or temp table or CTE).OR Is there any way to parse the multiple values into a table. like if we pass multiple values into a parameter. those should go into a table as rows.

View 6 Replies View Related

How To Match The Date Variable And Character Variable

Oct 9, 2001

Hello,
I run the DTS to copy data from Progress to SQL Server. How can match/convert the date variables to check.
The field p-date as format 'mm-dd-year' . It has the value of 10/09/2001.
The field s-date as varchar format. It has the value 2001-10-09.
How can use the where condition ( Select ...... WHERE p-date = s-date.)

Thanks

View 1 Replies View Related

Object Variable Or With Block Variable Not Set (was Frank)

Mar 7, 2005

When trying to upsize an access database to sql server using the upsize wizard, I get the following error:

"Object variable or With block variable not set."

Any assistance is greatly appreciated.

View 3 Replies View Related

Variable Indirection: Choosing Variable At Runtime

Oct 18, 2007

Hello!
I'm using SQL Server 2000.
I have a variable which contains the name of another variable scoped in my stored procedure. I need to get the value of that other variable, namely:

DECLARE @operation VARCHAR(3)
DECLARE @parameterValue VARCHAR(50)

SELECT @operation='DIS'

CREATE table #myTable(value VARCHAR(20))
INSERT into #myTable values('@operation')

SELECT top 1 @parameterValue = value from #myTable
-- Now @parameterValue is assigned the string '@operation'
-- Here I need some way to retrieve the value of the @operation variable I declared before (in fact
-- another process writes into the table I retrieved the value from), in this case 'DIS'

DROP TABLE #myTable



I've tried several ways, but didn't succeed yet!
Please tell me there's a way to solve my problem!!!

Thank you very much in advance!

View 7 Replies View Related

Integration Services :: Variable Value Does Not Fit Variable Type

May 27, 2015

I have an SSIS package that creates a csv file based on a execute sql task.

The sql is incredibly simple select singlecolumn from table.

In the properties of the execute sql task I specify the result set as "full result set" when I run it I get the error that: Error:

The type of the value being assigned to variable "User::CSVoutput" differs from the current variable type.

Variables may not change type during execution. Variable types are strict, except for variables of type Object.

If I change the resultset to single row then I only get the first row from the DB (same if I choose none), If I choose XML then I get the error that the result is not xml. What resultset type do I need to choose in order to get all the rows into the CSV? The variable I am populating is of type string and is User::CSVoutput

View 8 Replies View Related

Object Variable Or With Block Variable Not Set

Aug 17, 2004

While I was processing the cubes, error "Object Variable Or With Block Variable Not Set" prompt out,
what does it mean ?

Please help !!!

View 1 Replies View Related

Foreach From Variable Using 2 Dim Array Variable

May 15, 2007



Is there any way to use a 2 dimensional array of strings as the Variable Enumerator for the "Foreach From Variable Enumerator". I am trying to copy a collection of files from folder A to folder B. In a script, I would populate, let us say, an array of (2,10), for 10 files, with one column representing the source file and other column representing the target column task. Then I would like to set this string array variable as the "Variable Enumerator" for the "Foreach From Variable Enumerator" and use file system tasks in the foreach loop to perform the tasks. The problem is that the "Foreach From Variable Enumerator" does not let me choose an index, but passes only one index 0, so, I will only be able to pass just one column. How do I let the foreach enumerator let me choose an index. The other foreach enumerators, foreach item and ADO give me the option to select index. I would like the same functionality in the foreach variable.

Note: I cannot use the "For Each File" enumerator, since the files are to be selected by a script only.
Thanks for the help.

View 3 Replies View Related

Cannot Set A Variable From A Select Statement That Contains A Variable??? Help Please

Oct 4, 2006

I am trying to set a vaiable from a select statement

DECLARE @VALUE_KEEP NVARCHAR(120),

@COLUMN_NAME NVARCHAR(120)



SET @COLUMN_NAME = (SELECT COLUMN_NAME FROM INFORMATION_SCHEMA.COLUMNS WHERE TABLE_NAME = 'CONTACTS' AND COLUMN_NAME = 'FIRSTNAME')



SET @VALUE_KEEP = (SELECT @COLUMN_NAME FROM CONTACTS WHERE CONTACT_ID = 3)



PRINT @VALUE_KEEP

PRINT @COLUMN_NAME



RESULTS

-------------------------------------------------------------------------------------------

FirstName <-----------@VALUE_KEEP

FirstName <-----------@COLUMN_NAME



SELECT @COLUMN_NAME FROM CONTACTS returns: FirstName

SELECT FirstName from Contacts returns: Brent



How do I make this select statement work using the @COLUMN_NAME variable?

Any help greatly appreciated!

View 2 Replies View Related

Variable Inside A Variable From Sql TAsk

Sep 28, 2006

I've got two Sql Tasks on my dtsx. The first one loads a value into "Proyecto" user variable and the second one executes a variable named "SegundoProceso" which contains from the beginning:

"select Fecha from LogsCargaExcel where Proyecto = " + @[User::Proyecto] +""
As SqlSourceType propety I have "Variable" and inside ResultSet or Parameter Mapping nodes there is nothing.

[Execute SQL Task] Error: Executing the query ""select Fecha from LogsCargaExcel where Proyecto = " + @[User::Proyecto] +""" failed with the following error: "Cannot use empty object or column names. Use a single space if necessary.". Possible failure reasons: Problems with the query, "ResultSet" property not set correctly, parameters not set correctly, or connection not established correctly.

Where am I wrong?

TIA

View 12 Replies View Related

SQL Variable And IS Variable In Execute SQL Task

Jan 3, 2007

Hi,

 

I have an Execute SQL Task (OLE DB Connnection Manager) with a SQL script in it. In this script I use several SQL variables (@my_variable). I would like to assign an IS variable ([User::My_Variable]) to one of my SQL variables on this script. Example:

 

DECLARE @my_variable int

, <several_others>

SET @my_variable = ?

<do_some_stuff>

 

Of course, I also set up the parameter mapping.

However, it seems this is not possible. Assigning a variable using a ? only seems to work in simple T-SQL statements.

I have several reasons for wanting to do this:

- the script uses several variables, several times. Not all SQL variables are assigned via IS variables.

- For reading and mainenance purposes, I prefer to pass the variable only once. Otherwise every time the script changes u need to keep track of all questionmarks and their order.

- Passing the variable once also makes it easier to design the script outside IS using Management Studio.

- This script only does preparation for the actual ETL, so I prefer to keep it in one task instead of taking it apart to several consecutive Execute SQL Tasks.

- I prefer to use the OLE DB connection manager because it's a de facto standard here.

 

Could anyone help me out with the following questions:

- Is the above possible?

- If so, how?

- If not, why not?

- If not, what would be the best way around this problem?

 

Thanx in advance,

Pipo

View 6 Replies View Related

Set A System Variable To User Variable

May 21, 2007

How can I inside a DFT set a System variable, for example "TaskName" to an own created User Variable?



The reason is that I need to use this variable later in the Control Flow.



Regards



Riccardo

View 10 Replies View Related







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