I'm creating a table variable, then executing it in an EXEC statement, like this:
DECLARE @temp_table TABLE (
column1 INT,
column2 INT
)
SET @strInsert = 'INSERT INTO @temp_table (column1,column2) VALUES ('+@intValue1+','+@intValue2+')'
EXEC (@strInsert)
I get a message during the EXEC statement that I must declare @temp_table. When I do this using an actual temporary table (i.e. #temp_table) instead, it works fine. Is there a way around this so I can use the variable instead of the table?
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.
hello I have a problem with Sql task when sql task tried to assing a value to my variable I have this error ""La valeur n'est pas comprise dans la plage attendue." I'm using ODBC connexion for a csv file
[Execute SQL Task] Error: An error occurred while assigning a value to variable "JDETimezone": "Unable to find column Timezone in the result set.".
i know what the problem is i.e. no row is returned then what is the problem
here you are.... i want to it work... strange... ok i explain...
actully i have some processign to do with variable JDETimezone even no row is returned.... can u tell me the alternative to do the follwing task...
I want to retrieve a record from some table and do some processing and if no row is present or returned then i want to do seperate processing.... can ne one help me out ?
Simple example: declare @tTable(col1 int) insert into @tTable(col1) values (1) select * from @tTable
Works perfectly in SQL Server Management Studio and the database connection is OK to as I may generate PP table using complex (or simple) queries without difficulty.
But when trying to get this same result in a PP table I get an error, idem when replacing table variable by a temporary table.
Message: OLE DB or ODBC error. .... The current operation was cancelled because another operation the the transaction failed.
I am trying to use a stored procedure to update a column in a sql table using the value from a variable table I getting errors because my syntax is not correct. I think table aliases are not allowed in UPDATE statements.
This is my statement:
UPDATE [dbo].[sessions_teams] stc SET stc.[Talks] = fmt.found_talks_type FROM @Find_Missing_Talks fmt WHERE stc.sessionid IN (SELECT sessionid FROM @Find_Missing_Talks) AND stc.coupleid IN (SELECT coupleid FROM @Find_Missing_Talks)
Can someone tell me if it is possible to add an index to a Table variable that is declare as part of a table valued function ? I've tried the following but I can't get it to work.
ALTER FUNCTION dbo.fnSearch_GetJobsByOccurrence ( @param1 int, @param2 int ) RETURNS @Result TABLE (resultcol1 int, resultcol2 int) AS BEGIN
my stored procedure have one table variable (@t_Replenishment_Rpt).I want to create an Index on this table variable.please advise any of them in this loop... below is my table variable and I need to create 3 indexes on this...
Hi, I have application in which i am performing synchronization between SQL Server 2000 and SQL Server 2005 CE. I have one table "ItemMaster" in my database.There is no relationship with this table,it is standalone.I am updating its values from Windows Mobile Device.
I am performing below operations for that. Step : 1 Pull To Mobile
Code BlockmoSqlCeRemoteDataAccess.Pull("ItemMaster", "SELECT * FROM ItemMaster", lsConnectString,RdaTrackOption.TrackingOn);
Step : 2 Using one device form i am updating table "ItemMaster" table's values.
So i am getting an error on 3rd step. While i am trying to push it says, "The Push method returned one or more error rows. See the specified error table. [ Error table name = ]". I have tried it in different ways but still i am getting this error.
Note : Synchronization is working fine.There is not issue with my IIS,SQL CE & SQL Server 2k.
Can any one help me?I am trying for that since last 3 days.
Hi All,Hope someone can help me...Im trying to highlight the advantages of using table variables asapposed to temp tables within single scope.My manager seems to believe that table variables are not advantageousbecause they reside in memory.He also seems to believe that temp tables do not use memory...Does anyone know how SQL server could read data from a temp tablewithout passing the data contained therein through memory???Is this a valid advantage/disadvantage of table variables VS temptables?
SQLLY challenged be gentle --Trying to create code that will drop a table using a variable as theTable Name.DECLARE @testname as char(50)SELECT @testname = 'CO_Line_of_Business_' +SUBSTRING(CAST(CD_LAST_EOM_DATEAS varchar), 5, 2) + '_' + LEFT(CAST(CD_LAST_EOM_DATE AS varchar),4)+ '_' + 'EOM'FROM TableNamePrint @testname = 'blah...blah...blah' (which is the actual tablename on the server)How can I use this variable (@testname) to drop the table? Undersevere time constraints so any help would be greatly appreciated.
In a previous post "Could #TempTable within SP cause lock on tempdb?" http://forums.microsoft.com/msdn/showpost.aspx?postid=2691763&siteid=1
It was obvious that we have to limit the use of #Temp table to a minimum. Let assume that some of the temp tables are really difficult to replace and we have to live with them.
Would it be easier on tempdb if the #TempTable is replaced by a table variable? Or do they all end up in tempdb?
I have a stored produre. Inside this stored procedure I have table variable with one column. Once the table variable is populated with rows, I would like to pass each value in the table, into a table-valued function. The table-valued function may return any number of rows. I would like all the rows the TVF returns to be returned from the stored procedure as a single result set. I would also like to do this without defining a table variable to hold the results of the table-value function.
Code Snippet
declare @IdTable table ( EmployeeId nvarchar( 16 ) not null ) insert into @IdTable select EmployeeNumber from Employees
/* I need to run this query for every EmployeeId value in @IdTable and return the results from the stored proc as a single result set. */ select * from fn_GetEmployeeById( EmployeeId )
In my stored procedure i have a multi-valued varchar(max) parameter and I wrote a table-valued function that takes the varchar(max) and return a table back to the stored procedure where i inserted into a @table. Just wondering is there a better and faster way of doing this?
ALTER PROCEDURE [dbo].[rpt]
(
@CourtIDs as nvarchar(MAX) -- @CourtIDs = '1231,3432,1234,3421'
) AS
--split CourtIDs into a table DECLARE @tbCourtIDs table(CourtID int NOT NULL PRIMARY KEY) INSERT INTO @tbCourtIDs select * from dbo.Split(@CourtIDs, ',')
hi all, if i have a function which it returns a table and i need to work with the table retured many times in the stored procedure, then should i use a temporary table or a table variable to store the returned table ? or it's there a better way in doing that?
I want to save some temporal data in the stored procedure. Comparing temporal table and table type variable, which one is better regarding to the performance?
I'm trying to set up a simple package that can be run after other packages to move packagelog files to another folder(I'm doing this because it doesn't look like we can overwrite a package log file and I really don't want to have to manually keep these in check). Anyway, I've got a source variable and a destination variable. I'm using an expression to build these values in the File System Task. When I run the package I get this error :
Error: 0xC0014054 at CopyPackageLog: Failed to lock variable "C:TempMyPackageLog.xml" for read access with error 0xC0010001 "The variable cannot be found. This occurs when an attempt is made to retrieve a variable from the Variables collection on a container during execution of the package, and the variable is not there. The variable name may have changed or the variable is not being created."
It looks like the variables are getting loaded with the correct path names. Any suggestions?
I am getting a strange error when trying to set a variable from a Execute SQL task. The error I get is below:
[Execute SQL Task] Error: An error occurred while assigning a value to variable "MpxBeginOrderNbr": "The type of the value being assigned to variable "User::MpxBeginOrderNbr" differs from the current variable type. Variables may not change type during execution. Variable types are strict, except for variables of type Object. ".
The variable MpxBeginOrderNbr is DataType Int32
The sql statement I am executing is:
SELECT MIN(OrderNbr) AS MpxBeginOrderNbr FROM dbo.vCrmOrderHeader WHERE OrderDate > DATEADD(MONTH, -?, GETDATE())
OrderNbr in the View vCrmOrderHeader is datatype BIGINT. I have tried changing the MpxBeginOrderNbr variable to Int64 but I get the same error message. In my test data the result set returns the number 1 which is the first order. Is this a bug in SSIS or am I missing something?
Help! I am writing a cursor that goes out and retrieves all the tables that contain a certain column name and then inserts specific data from those tables into a new table. The problem i'm having is even though I can load the table names into a variable I can't use that variable as a table name to do the insert. It gives me an error that the variable hasn't been declared even though it has. Is there any tricks I can do to make SQL treat the variable as a table name so I can run the Insert from these table names?
Dave
Here is the what I've got so far:
Declare @table_name varchar Declare table_name_cursor CURSOR FOR SELECT TABLE_NAME FROM INFORMATION_SCHEMA.TABLES as t, syscolumns as s WHERE t.TABLE_NAME = OBJECT_NAME((s.ID)) and s.Name='ModBy'and t.Table_Type = 'Base Table'
I have a UDF that will return a fully qualified table name given a few parameters. What I would like to do is call my UDF in a SQL statement and NOT have to use the sp_executesql and pass my query in as a string.
The reason for this is I have no promises from my client of the server and database name for the tables that I am going to use so I would like to build a UDF that I could change the server name and database name in ONE place and have all my queries using the right database. I basically have 3 "applications' that I need to do business with. For simplicity sake we'll just call them 'APP1','APP2','APP3'.
Example:
If my table is called 'TABLEA' and it's a table for 'APP1', what I have is UDF where you pass in the application and table and it returns the fully qualified path to the table. For example:
Select @TheTableName = dbo.MYUDF('app1','tablea')
Result is @TheTableName would be 'SERVER_FOR_APP1.DBO.TABLEA'
What I have found that I had to do is build a nvarchar(????) string of my query and then call sp_executesql and pass it the query via the nvarchar string. There are cases where this will not work - For example:
Select @somevalue = sometable.field from server_for_app1.dbo.sometable where someprimarykey = 123
Ideally I could code this as:
Select @somevalue = sometable.field from MyUDF('APP1','SOMETABLE') where someprimarykey = 123
Again, "MyUDF" returns a varchar() of the fully qualified table name including server and database name.
Does anyone know how I can make this work?
Thanks for any help you can provide and apologies for any cross posting!
is it possible to create a temp table and iterate through each database in the temp table? Something like and this would iterate both tables in the databse and display the results. (Of course I would actually be doing this on a much larger scale and not just selecting *
Code: Declare @CountCheck int Create table #databse