Hi,
In a stored procedure (MS SQL) I want to update a table to Add columns to it, and then update those new columns with data from a variable.
The problem is that, after updating the table I add a GO, the variable value is loss, but if I don't add the GO I get the error that the column Im adding value to don't exist.
o_O
Example: -
-
CREATE PROCEDURE dbo.myProcedure_SP
-
(
-
@var1 int = 1,
-
@var2 int = 1
-
)
-
-
AS
-
-
-
ALTER TABLE myTable
-
ADD column1 INT NULL
-
column2 INT NULL,
-
-
UPDATE myTable
-
SET column1 = @var1,
-
column2 = @var2
-
-
GO
-
-
EXEC myProcedure_SP
-
-
-
Any ideas how to work around this? Thanks!
1 2846
I'm not sure what your overall aim is here. Why are you creating a sp and then attempting to run it straight away? If this is a creation script why have an sp, just run the alter and update statements directly. If you need to reference variables throughout a long creation script that include proc creations try creating a temp table at the start to hold all your reused parameters then assign from that table as required.
Are you attempting some dynamic table control from another app?
Sign in to post your reply or Sign up for a free account.
Similar topics |
by: Peter Gorelczenko |
last post by:
Good Morning,
I'm running Alpha 4.1 on Linux. I'm new to MySql but familliar with othe=
r=20
databases. I set up a user with "Create Temporary Tables" permissions. =
That=20
user can create temp tables but can not alter or update the table. That=
=20
user is getting "Update command denied to user..." for the temp table. =
They=20
also get this error when an alter table is executed. Doesn't the user ha=
|
by: FRED |
last post by:
hi all,
i have a table that has a column date varchar(20) and now i learned some
more about mysql I want to make it date date but if I do an alter table on
it what will it do to my existing data which currently is in the format 11
June 2004 (but in a varchar type).
many thanks!
F
|
by: Stephen Miller |
last post by:
Is it possible to ALTER a temporary table in TSQL (SQL2000)?
The following TSQL reports a syntax error at the ALTER TABLE line:
DECLARE @Test TABLE(
NOT NULL ,
NOT NULL
)
ALTER TABLE @Test
DROP COLUMN Col2
|
by: Bruce |
last post by:
Hi,
I want to change the datatype of an existing column from char to
varbinary. When I run the "Alter Table" statement, I get the
following error message -
Disallowed implicit conversion from data type char to data type
varbinary, table 'test.dbo.testalter', column 'col1'. Use the CONVERT
function to run this query.
|
by: maricel |
last post by:
Could someone confirm which tablespace is being used when running ALTER &
CREATE INDEX.
Is it the tempspace or the tablespace where the table resides?
Many thanks,
maricel
| |
by: Jeff Kish |
last post by:
Hi.
I have a database I need to supply something (I'm assuming a t-sql script..
maybe something else is better) to update customer tables with.
The operations include mostly changing varchar lengths, though a couple of
columns were renamed.
I'd like to maybe figure out how to get Enterprise Manager or Query Analyzer
to generate the scripts.
|
by: RamaKrishna Narla |
last post by:
In MS SQL Server, I have the following tables with some data in it.
create table table1 (
column1 varchar(32),
column2 int not null,
column10 varchar(255),
.....
primary key (column1, column2),
);
|
by: Brian Wotherspoon |
last post by:
Hi all,
I'm using SQL Server 2000 SP3 to store data for real time transaction
processing.
I have set up replication to another server using a push subscription to
give me immediate backup.
I need to alter the data type of one of the columns and am using the
following basic sql:
|
by: Serge Rielau |
last post by:
Hi all,
Following Ian's passionate postings on problems with ALTOBJ and the
alter table wizard in the control center I'll try to explain how to use
ALTOBJ with this thread. I'm not going to get into the GUI because it is
hard to describe in text.
First of all what is the purpose of ALTOBJ()?
This procedure was created mostly for ISVs who need to do produce change
scripts to upgrade application from release to release, but it can also
|
by: marktang |
last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look !
Part I. Meaning of...
|
by: Hystou |
last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it.
First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
| |
by: Oralloy |
last post by:
Hello folks,
I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>".
The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed.
This is as boiled down as I can make it.
Here is my compilation command:
g++-12 -std=c++20 -Wnarrowing bit_field.cpp
Here is the code in...
|
by: Hystou |
last post by:
Overview:
Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
|
by: tracyyun |
last post by:
Dear forum friends,
With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
|
by: agi2029 |
last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own....
Now, this would greatly impact the work of software developers. The idea...
|
by: adsilva |
last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
|
by: muto222 |
last post by:
How can i add a mobile payment intergratation into php mysql website.
| |
by: bsmnconsultancy |
last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...
| |