SET IDENTITY_INSERT Tablename ON

Nov 15, 2007

I use IDENTITY(1,1)
and the help says:
SET IDENTITY_INSERT tablename ON

But if the table is an variable(virtual) table how to make it work?


Like this:
DECLARE @TEMPtable table ( ID int Identity(1,1), invar nvarchar(255)


It does not work with
SET IDENTITY_INSERT @TEMPtable ON

I get this

'Incorrect syntax near '@TEMPtable '

View 12 Replies


ADVERTISEMENT

SET IDENTITY_INSERT Tablename ON

Sep 16, 2006

I know there has already been a thread on this, but I want to push some about it.

In SQL Server, there is a command "SET IDENTITY_INSERT tablename ON".

That allows you to update IDENTITY columns, or do INSERTs that include IDENTITY columns. Although a work-around was given for this in the other thread (reset the IDENTITY seed to the desired value before each INSERT), that is a major pain.

In my database, I have a table that tracks charitable donors. They have a donornum, that is an IDENTITY column, and a year. Together, the donornum and the year form the primary key. Each year end, a copy is made of all donor records in one year, to form the next year's donors. They have to keep the same donornum, but they get a new year value of course. Adding new donors uses the donornum normally, incrementing the IDENTITY donornum value.

The advantage of this is that you can match up one year's donors with the previous year's, by joining on donornum. But I need there to be separate records, so they can have separately updated addresses, annual pledge amounts, etc.

Is there any way the SET IDENTITY_INSERT feature can be added to SQL Everywhere, or some other approach can be found that is less laborious than the existing work-around? (The problem with it is that if you have hundreds of donors to copy, you have to do one ALTER TABLE to reset the identity seed for each donor insert for the new year.)

Thanks.

View 4 Replies View Related

How To Use @tablename

Feb 12, 2005

i need to develop a stored procedue, in ehich i have to use variable table name.. as Select * from @tableName but i m unable to do so..
it says u need to define @tablename

heres da code
CREATE PROCEDURE validateChildId
(
@childId int,
@tableName varchar(50),
@fid int output
)
AS
(
SELECT @fid=fid FROM @tableName
where @childId= childId
)

if @@rowcount<1
SELECT
@fid = 0
GO

View 4 Replies View Related

Tablename

Aug 2, 2007

Hi,
i just migrated an database from oracle to sql server 2005 with the migration tool from microsoft (v3). the migration tool works only with uppercase table and column names, but i need them in lower case. is there a way to modify the names of tables and columns with t-sql to lower case?
Thx
Frank

View 2 Replies View Related

IDENTITY_INSERT Is Set To OFF

Dec 5, 2005

I am trying to insert a new record to a table in my application created by VWD Express. I get beack the responce "Cannot insert explicit value for identity column in table 'Tradersa' when IDENTITY_INSERT is set to OFF" . I have a key record in the table which I would like to increment automatically as I add records so I have set the is identity value to true and both the identity seed and increment to 1.
I have done a fair bit or searching but do not know how to set the table value of IDENTITY_INSERT to ON. Is this as the table is set up or as the record is about to be added? I beleive I should set this when I add the record, but do not know how to in VWD.
Any help would be most welcome. Many thanks in advance

View 4 Replies View Related

Set Identity_insert

Apr 23, 2001

Hi
--SQL SERVER 7.0
I have a table P1 which has one identity column and 9 other columns.
i need to put all the data from this table into another table with same structure as P1 called P2.

even though i used Set identity_insert P2 on
I get an error saying column list must be specified
Basically i was trying to do this

SET IDENTITY_INSERT P2 ON
go
insert into P2
select * from P1

could somebody throw light onto how to specify the column list,but at the same time inserting the entire data from P1 in one shot(using select * from...)?

Any help ragarding this is highly appreciated
Thanx
SK

View 2 Replies View Related

SET IDENTITY_INSERT

Mar 17, 2000

The SQL Server 7 documentation says "SET IDENTITY_INSERT permissions default to all users".

I run this command:

SET IDENTITY_INSERT database.dbo.tablename ON

I am getting an error

Server: Msg 8104, Level 16, State 1, Line 1
The current user is not the database or object owner of table

1) Is this an error in the documentation?

2) If so, is there a way I can grant rights to a non-dbo account to perform this?

Thanks

View 1 Replies View Related

Identity_insert?

Nov 11, 2007

I need to archive from one table to another but the new table, which is a duplicate of the old one, won't allow inserts into the ID column.
I am using:
set identity_insert soldVehicles on
INSERT INTO soldVehicles
SELECT *
FROM vehicles
Where sent2sold = 'yes'
but I get this error:
Error -2147217900


An explicit value for the identity column in table 'soldVehicles' can only be specified when a column list is used and IDENTITY_INSERT is ON.

set identity_insert soldVehicles on
INSERT INTO soldVehicles
SELECT *
FROM vehicles
Where sent2sold = 'yes'

As I have turned ID_insert ON it must be the column list?...
not sure what to do next.

View 14 Replies View Related

Set Identity_insert

Dec 24, 2007

hi

i need to set the identity_insert on and off to a remote table in order to insert rows into it

can anyone help me please

View 11 Replies View Related

Identity_insert

Aug 28, 2006

my SP worked on friday, then today i ran it, but it's not working and throws these errors. i googled the error, but i still can't fix it. can you help me?


Server: Msg 8101, Level 16, State 1, Procedure USP_Trio_Popul_Stg_Tbls, Line 31
An explicit value for the identity column in table 'dbo.Name_Pharse_Stg_Tbl2' can only be specified when a column list is used and IDENTITY_INSERT is ON.
Server: Msg 8101, Level 16, State 1, Procedure USP_Trio_Popul_Stg_Tbls, Line 57
An explicit value for the identity column in table 'dbo.Name_Pharse_Stg_Tbl3' can only be specified when a column list is used and IDENTITY_INSERT is ON.

View 4 Replies View Related

IDENTITY_INSERT

Mar 31, 2008

I have 2 databases, HS and BoardAnalyst and the table TCompanies exist in both. I want to delete all of the records from HS.TCompanies and repopulate it with data from BoardAnalyst.TCompanies. I'm getting the error message "Table 'HS.dbo.CompID' does not exist or cannot be opened for SET operation." CompID is the PK for the table. I'm not sure what the problem is. Thanks



DELETE FROM HS.dbo.TCompanies
GO

SET IDENTITY_INSERT HS.dbo.TCompanies ON
GO

INSERT INTO HS.dbo.TCompanies
(
HS.dbo.AnnualMtg,
HS.dbo.BdMtgs,
HS.dbo.CompanyName,
HS.dbo.CompID,
HS.dbo.DirectorsTotal,
HS.dbo.Exchange,
HS.dbo.IndexFortune,
HS.dbo.Industry,
HS.dbo.LinkComp,
HS.dbo.MailAddress,
HS.dbo.MailCity,
HS.dbo.MailCountry,
HS.dbo.MailFax,
HS.dbo.MailingAddress1a,
HS.dbo.MailingAddress2,
HS.dbo.MailPhone,
HS.dbo.MailPostCode,
HS.dbo.MailState,
HS.dbo.MarketCap,
HS.dbo.ProxyDate,
HS.dbo.Revenues,
HS.dbo.StateHQ,
HS.dbo.Ticker,
HS.dbo.Updated
)

SELECT
BoardAnalyst.dbo.TCompanies.AnnualMtg,
BoardAnalyst.dbo.TCompanies.BdMtgs,
BoardAnalyst.dbo.TCompanies.CompanyName,
BoardAnalyst.dbo.TCompanies.CompID,
BoardAnalyst.dbo.TCompanies.DirectorsTotal,
BoardAnalyst.dbo.TCompanies.Exchange,
BoardAnalyst.dbo.TCompanies.IndexFortune,
BoardAnalyst.dbo.TCompanies.Industry,
BoardAnalyst.dbo.TCompanies.LinkComp,
BoardAnalyst.dbo.TCompanies.MailAddress,
BoardAnalyst.dbo.TCompanies.MailCity,
BoardAnalyst.dbo.TCompanies.MailCountry,
BoardAnalyst.dbo.TCompanies.MailFax,
BoardAnalyst.dbo.TCompanies.MailingAddress1a,
BoardAnalyst.dbo.TCompanies.MailingAddress2,
BoardAnalyst.dbo.TCompanies.MailPhone,
BoardAnalyst.dbo.TCompanies.MailPostCode,
BoardAnalyst.dbo.TCompanies.MailState,
BoardAnalyst.dbo.TCompanies.MarketCap,
BoardAnalyst.dbo.TCompanies.ProxyDate,
BoardAnalyst.dbo.TCompanies.Revenues,
BoardAnalyst.dbo.TCompanies.StateHQ,
BoardAnalyst.dbo.TCompanies.Ticker,
BoardAnalyst.dbo.TCompanies.Updated
FROM
BoardAnalyst.dbo.TCompanies
GO


SET IDENTITY_INSERT HS.dbo.CompID OFF
GO

View 1 Replies View Related

IDENTITY_INSERT

Apr 23, 2008



I have a table where IDENTITY_INSERT is set to OFF. I also have one stored procedure that I need to run that requires IDENTITY_INSERT to be set to ON. The only problem is the users who run the stored procedure are not owners of the table and are getting the error "The current user is not the database or object owner of table ... Cannot perform SET IDENTITY_INSERT" Is there a way to use the IDENTITY_INSERT command without being the owner of the object?

View 5 Replies View Related

SET IDENTITY_INSERT For SQL CE And SQL ME

Sep 30, 2007



Hi,

I have Product table in SQL Server 2005 with Primary key ProductID. This is column with Identity set so the values for this column is auto-generated. I also have Orders table has a key that is foreign key to table Products. Now my dev environment has SQL ME whereas the deployment will be done on SQL CE.

Now I have a requirement where we want to synchronize the master tables from SQL Server with the device. For this we want to have the same identity values on the device. When I try to issue SET IDENTITY_INSERT Products ON on SQL ME it does not work. Is there any way I can set the identity ON on the SQL Mobile Edition?

Also another question I have is: Is SET IDENTITY_INSERT supported on SQL Compact Edition?

Regards,
vnj

View 3 Replies View Related

SET IDENTITY_INSERT

Mar 24, 2006

We have created an "AdminUser" with the bare minimum rights for the activites it will need to do. One thing the "AdminUser" will need to do is a "SET IDENTITY_INSERT ON/OFF".

I understand that for this user to be able to do this they will need ddl_admin rights. But that gives them all kinds of permission that I don't want this user to have.

Is there a specific permission I can give the user so they can do the "IDENTITY_INSERT"?

I tried "GRANT create table to AdminUser" but that didn't work. I tried "GRANT alter any database DDL trigger to AdminUser" but that didn't work either. I'm looking for something more specific than "ddl_admin".

Thanks.

Trish

View 5 Replies View Related

Using Parameter In SP As Tablename

Jul 20, 2000

Does anyone know the syntax to reference a table in a stored procedure using a parameter? I'm trying to make a stored procedure that will "SELECT INTO" a table as the passed parameter. I keep getting an syntax error when I use this:

CREATE PROCEDURE make_table
@tablename varchar(20)
AS
SELECT * FROM old_table
INTO @tablename

I've tried it several ways, but I can't get it to work, and I haven't found any examples of this anywhere. Thanks in advance for any tips.

View 1 Replies View Related

&<Tablename&> . . &<ColumnName&>

Apr 30, 2004

Hi,
What is the difference between
<Tablename> . . <ColumnName> and <Tablename> . <ColumnName>
this syntax we are using in Storedprocedures.
In SQL 2000, <Tablename> . . <ColumnName> is not working

Eg:
Tablename =a
Column Name = b
Difference between a..b and a.b

Can anyone let me know.

TIA,
Ravi

View 2 Replies View Related

When IDENTITY_INSERT Is Set To OFF. -- LINQ

Jan 21, 2008

I'm new to ASP/VS/Linq and I'm having a small problem.
 I have one table setup in SQL Server Express 2005 through Visual Studio 2008.  The table name is "Users" and has three columns (accountID, userName, email).  AccountID is the primary key and set to auto incriment.  I've added a couple of records by hand and it works.
I have a single form with a button, a label, and two text boxes.  The button code is below.  After entering some fake data that does not already exist in the database and clicking the button I get this.
Cannot insert explicit value for identity column in table 'Users' when IDENTITY_INSERT is set to OFF.
I understand that it is trying to insert something into the accountID field but I don't understand why since I'm only providing a username and e-mail address to insert.
Your help is greatly appreciated.protected void Button1_Click(object sender, EventArgs e)
{
MyDatabaseDataContext db = new MyDatabaseDataContext();
var query = from u in db.Users
where u.email == txtEmail.Text
select u;

var count = query.Count();
if (count == 0)
{
//Create a new user object.
User newUser = new User();

newUser.username = txtUsername.Text;
newUser.email = txtEmail.Text;

//Add the user to the User table.
db.Users.InsertOnSubmit(newUser);
db.SubmitChanges();
}
else
{
Label1.Text = txtEmail.Text + " already exists in the database.";

 

View 6 Replies View Related

Error : IDENTITY_INSERT Is Set To OFF !

Mar 30, 2008

Hi,
What is this error ? 
Error : " Cannot insert explicit value for identity column in table 'Comments' when IDENTITY_INSERT is set to OFF. "
Please help me .

View 2 Replies View Related

Turning IDENTITY_INSERT ON

Aug 22, 2001

Im trying to do an INSERT SELECT statement in the following manner:

INSERT INTO
DB1.dbo.TABLE
SELECT *
FROM dbo.TABLE1
dbo.TABLE2 ON dbo.TABLE1.column = dbo.TABLE2.column

And Im given this error message:

An explicit value for the identity column in table 'DB1.dbo.TABLE' can only be specified when a column list is used and IDENTITY_INSERT is ON


So if anyone knows how to turn it on it would be a great help.

Sincerely,
Matt

View 3 Replies View Related

SET IDENTITY_INSERT ON/OFF Error

Mar 22, 2007

I would like to insert an indentity column explicitly following error occurs:

Server: Msg 544, Level 16, State 1, Line 1
Cannot insert explicit value for identity column in table 'TableMarket' when IDENTITY_INSERT is set to OFF.

And when I am trying to SET IDENTITY_INSERT ON, it gives following error:

Server: Msg 156, Level 15, State 1, Line 1
Incorrect syntax near the keyword 'ON'.

Anyone can help me please?

P.S. I am working on SQL Server 2000

Thanks,
Riaz

View 1 Replies View Related

Setting The IDENTITY_INSERT

Feb 23, 2004

is there any way i can set IDENTITY_INSERT = ON
permenately for the whole DB

View 2 Replies View Related

Identity_Insert Error

Apr 21, 2008

Hi all. This is my first post to these forums and I am a newbie. I am using SQL server 2005 and I have written a procedure to insert the data in new row. My procedure runs and executes well, but does not insert a record in my DB table. Instead I get a message in the debugger window that I need to turn ON the Identity Insert property for the tables. But after searching for a while in the IDE, I could not find any such property. So I need to know what went wrong here. Also, I am using ASP.NET to connect to the database and I found out an article on web explaining the way to set the property to ON through my ASP.NET application. But, I would also like to know how to set that property to ON through SQL management studio. Also, my primary key is not null; I am also passing the primary key value and it is unique. Please let me know a remedy for this.



Thank you.

View 15 Replies View Related

Problem With SET IDENTITY_INSERT

Sep 10, 2007

Hi,
I am facing problem while inserting data in a table having identity seed.

DECLARE @varSQL VARCHAR(8000)
DECLARE @VARe VARCHAR(400)

SET @VARe = 'Tmp_r429_sig'
SET @varSQL ='SET IDENTITY_INSERT ' + @VARe + ' ON'
EXEC (@varSQL)

INSERT INTO Tmp_r429_sig ([NAME],ID) VALUES('test',1)

SET @varSQL ='SET IDENTITY_INSERT ' + @VARe + ' OFF'
EXEC (@varSQL)

The table name need to be a variable.

I ma getting following error:
Server: Msg 544, Level 16, State 1, Line 1
Cannot insert explicit value for identity column in table 'Tmp_r429_sig' when IDENTITY_INSERT is set to OFF.

Can someone throw some light on how to execute SET IDENTITY_INSERT as a dynamic query.

View 3 Replies View Related

Problems With IDENTITY_INSERT

Mar 27, 2008

Hey Everyone,

I'm trying to copy the data from one table to another while preserving the identity keys, but I can't seem to get past this error message. Here's the SQL:

SET IDENTITY_INSERT dbo.Cms_MenuItems_Preview ON

INSERT INTO dbo.Cms_MenuItems_Preview
SELECT Id, [Name], Url, Parent, IsActive, SortIndex
FROM dbo.Cms_MenuItems

SET IDENTITY_INSERT dbo.Cms_MenuItems_Preview OFF


and the error message is:
Msg 8101, Level 16, State 1, Line 3
An explicit value for the identity column in table 'dbo.Cms_MenuItems_Preview' can only be specified when a column list is used and IDENTITY_INSERT is ON.

Any suggestions?

Thanks in advance!

View 3 Replies View Related

IDENTITY_INSERT Problem

Jul 20, 2005

Hi, I am having a problem with IDENTITY_INSERT command with MSDE 2000 (ADO2.8) in that I cannot insert a specific value to an identity field. (linesbelow with >>> are code lines. I am using Python, but the syntax should beabout the same as VBScript)First, I create an ADO Connection and create my table.[color=blue][color=green][color=darkred]>>> c = win32com.client.Dispatch('ADODB.Connection')[/color][/color][/color][color=blue][color=green][color=darkred]>>> dsn = 'DRIVER=SQL[/color][/color][/color]Server;UID=myID;Trusted_Connection=Yes;Network=DBM SSOCN;APP=Microsoft DataAccess Components;SERVER=SERVERINSTANCE;"'[color=blue][color=green][color=darkred]>>> c.Open(dsn)[/color][/color][/color][color=blue][color=green][color=darkred]>>> sql = 'CREATE TABLE Table_Name ('[/color][/color][/color][color=blue][color=green][color=darkred]>>> sql += 'ID_Field INTEGER PRIMARY KEY IDENTITY(1,1), '[/color][/color][/color][color=blue][color=green][color=darkred]>>> sql += 'Field_2 nchar(50) NOT NULL, '[/color][/color][/color][color=blue][color=green][color=darkred]>>> sql += 'Field_3 FLOAT DEFAULT 0.0)'[/color][/color][/color][color=blue][color=green][color=darkred]>>> c.Execute(sql)[/color][/color][/color]This works fine. Then, I attempt to allow insertion into the ID_Field.[color=blue][color=green][color=darkred]>>> c.Execute("SET IDENTITY_INSERT Table_Name ON")[/color][/color][/color]This seems to work in that it does not throw an error and gives a returnof -1. Then I open a Recordset[color=blue][color=green][color=darkred]>>> r = win32com.client.Dispatch('ADODB.Recordset')[/color][/color][/color][color=blue][color=green][color=darkred]>>> r.Open('Table_Name', c, 2, 4)[/color][/color][/color]Last, I am attempt to add a record to the recordset with an explicit ID,[color=blue][color=green][color=darkred]>>> r.AddNew()[/color][/color][/color][color=blue][color=green][color=darkred]>>> r.Fields.Item('ID_Field').Value = 45[/color][/color][/color]but this fails with the error of"Multiple-step OLE DB operation generated errors. Check each OLE DBstatus value, if available. No work was done."Even worse, if I now try to set the identity field to allow inserts again,Updating() causes an error that I must use an explicit value for ID_Field,but if I try to give it one, it fails with the above error. I have todestroy the recordset object at this point to get any further.I am told that SET IDENTITY_INSERT only remains active for one statement andthus must be combined with the insert, but I do not know how to do this.There is a similar sounding bug w/ SQL 7(http://support.microsoft.com/defaul...b;EN-US;253157), but thereis no indication that it affects newer versions of the DB. Does anyone haveany suggestions or ideas?Thanks for any help,-d

View 1 Replies View Related

Unable To Set Identity_Insert Off?

Jan 24, 2007

Hi i am unable to set Identity_insert off in sql server compact? Can you please tell me if sqlce supports or not?

If it does not support what is the work around that can be done?

Please tell the workaround in detail i mean altering table for identity key e.g. Because i have seen some posts that talk about alter table but i am unable to understand how that can done?

Thanks

View 7 Replies View Related

IDENTITY_INSERT Issue

Jun 7, 2007

INSERT INTO dbo.my_table (table_key)
VALUES (007)

-- Msg 544, Level 16, State 1, Line 1
-- Cannot insert explicit value for identity column in table 'my_table' when IDENTITY_INSERT is set to OFF.



SET IDENTITY_INSERT dbo.my_table ON
INSERT INTO dbo.my_table(table_key)
VALUES (007)
SET IDENTITY_INSERT dbo.my_table OFF

-- Msg 1088, Level 16, State 11, Line 2
-- Cannot find the object "dbo.my_table" because it does not exist or you do not have permissions.

I know for certain that I have read/write permissions on this server. Is this somehow restricted to only the dba or something?

I appreciate all of this community's help with my basically non-stop flow of questions. You're a huge chunk of help, and it's deeply appreciated!!

Jim Work

View 4 Replies View Related

IDENTITY_INSERT On/Off In Sql Compact

Dec 11, 2006

Hi,

Im working in a project that uses sql server compact. While migrating some data from another database I needed to "Turn off" the identity insert :

SET IDENTITY_INSERT <tablename> OFF

and set it back to "ON" after the migration was completed. Unfortunately SQL Server Compact is giving me the following error:

There was an error parsing the query. [ Token line number = 1,Token line offset = 5,Token in error = @@IDENTITY_INSERT ]

Im i doing something wrong or this instruction is not supported by the Compact edition.

Does anybody knows another way to do this?

Thank you

Alexander75



View 5 Replies View Related

Select * From Tablename Where Column1 In ()

Apr 4, 2008

Hi to all ,           I write the query like belwodeclare @userid nvarchar(20)set @userid ='6,8'print @useridselect * from user_master where user_id in (@userid)Here user_id  is int datatype, when i execute this query then meet the error as  6,8Msg 245, Level 16, State 1, Line 4Syntax error converting the nvarchar value '6,8' to a column of data type int. How to do this.? Anybody answer me,... 

View 5 Replies View Related

How Do I Select Tablename In Subquery

Feb 19, 2001

hi all how are you today i am not good because i can't set this variable in this query please read this thanks

create table aaa1 (id_no int, name varchar(20))
go
create table aaa2 (id_no int, name varchar(20))
go

insert into aaa1 values (1,'rahmi')
insert into aaa1 values (2,'atilganer')
insert into aaa1 values (3,'hasan')

insert into aaa2 values (4,'rahmi')
insert into aaa2 values (5,'atilganer')
insert into aaa2 values (6,'hasan')

/* declaring any numeric variable*/
declare @id_no_var int
/* and set variable to max table name's (aaa2 table in this example)
id_ no column*/

set @id_no_var =
(select max(id_no) from
(select max(name) insqlhelp from
sysobjects where name like 'aa%') insqlhelp2 )


this query return:

Server: Msg 207, Level 16, State 3, Line 3
Invalid column name 'id_no'.

this error returned in second

View 1 Replies View Related

How Do I Select Tablename In Subquery

Feb 19, 2001

hi all how are you today i am not good because i can't set this variable in this query please read this thanks

create table aaa1 (id_no int, name varchar(20))
go
create table aaa2 (id_no int, name varchar(20))
go

insert into aaa1 values (1,'rahmi')
insert into aaa1 values (2,'atilganer')
insert into aaa1 values (3,'hasan')

insert into aaa2 values (4,'rahmi')
insert into aaa2 values (5,'atilganer')
insert into aaa2 values (6,'hasan')

/* declaring any numeric variable*/
declare @id_no_var int
/* and set variable to max table name's (aaa2 table in this example)
id_ no column

note :insqlhelp and insqlhelp2 is an alias for tablename query (recommended from sql help
*/

set @id_no_var =
(select max(id_no) from
(select max(name) insqlhelp from
sysobjects where name like 'aa%') insqlhelp2 )


this query return:

Server: Msg 207, Level 16, State 3, Line 3
Invalid column name 'id_no'.

this error returned because max(id_no) column is absent

if you are run
select * from
(select max(name) insqlhelp from
sysobjects where name like 'aa%') insqlhelp2

this query return that

insqlhelp ---------------
aaa2

(1 row(s) affected)

this mean that my table name query returned table name but i cant use this name in any other query (i think because of daclaring alias "insqlhelp, insqlhelp2")

other way is

set to any other text variable to table name,
and concetanate to query,
and execute with exec

but in this way you cant set to my int variable

please help me thanks for all

hra

View 1 Replies View Related

Using Cursor Variable As A Tablename

Oct 12, 2005

I am currently using a cursor to scroll through sysobjects to extract table names and then extracting relevant column names from syscolumns.

I then need to run the following script:

declare Detail_Cursor cursor for
select @colname, max(len(@colname)) from @table

The message I receive is "must declare variable @table".

Immediately prior to this script I printed out the result of @table which works fine so the variable obviously is declared and populated.

Can anyone let me know what I'm doing wrong or how I can get the same result.

Thanks

View 4 Replies View Related

Dynamic Tablename Issue

Apr 1, 2004

Dear all:
I have a storedprocedure for db loader form some temp tables.
my storedprocedure as the following:

declare c cursor
for
select * from @tablename
open c
fetch c into ....

but I get an error for declare cursor for dynamic tablename,

did sql server has some BIF to evaluate the variable for table name?

thanks for your kindly assistance.

regards,

Stanley Huang

View 4 Replies View Related







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