Hi folks,
I'm looking to pick everyone's brains.
I have a cursor, with over 200 columns in the select.
I am using a case in one of the columns which I'm retrieving, and want to issue an insert statement within this. i know people will come back with different merge or whatever, but i must be able to do this within a case statement unfortunately.
example
CURSOR c_student_data IS
SELECT a,
b,
CASE WHEN c = 1
THEN 'ONE'
WHEN c = 2
THEN 'TWO'
WHEN c = 3
THEN -- do 2 things if possible, display value as zz, and insert into another table.
'zz',
INSERT INTO error_table values(x,y,z)
END
d,
e
FROM t_table;
Now, i've spent quite a bit of time trying all different versions of this, can anyone shed some light on this please as I've not actually seen this being done before and can't find anything on the net regarding it.
Thanks in advance.
2 21110
you need to separate cursor fro the insert statment. insert statment can't be part of cursor.
check value in curson and based on that go for insert operation.
You cannot use an INSERT statement as a part of CASE WHEN in SELECT query. You can try something like this: -
-
INSERT INTO table_name SELECT (CASE WHEN 1 = 1 THEN 1 ELSE 2 END),column_2,column_3,column_4,column_5 FROM table_name WHERE (CASE WHEN 1 = 1 THEN 1 ELSE 2 END) = column_2;
-
-
Sign in to post your reply or Sign up for a free account.
Similar topics |
by: mirth |
last post by:
I would like to update a decimal column in a temporary table based on
a set of Glcodes from another table. I search for a set of codes and
then want to sum the value for each row matching the Glcodes. The
problem is I keep getting multiple rows returned errors.
"Subquery returned more than 1 value. This is not permitted when the
subquery follows =, !=, <, <= , >, >= or when the subquery is used as
an expression.
The statement has been...
|
by: Chad Richardson |
last post by:
I've always been mistified why you can't use a column alias in the group by
clause (i.e. you have to re-iterate the entire expression in the group by
clause after having already done it once in the select statement). I'm
mostly a SQL hobbiest, so it's possible that I am not doing this in the most
efficient manner. Anyone care to comment on this with relation to the
following example (is there a way to acheive this without re-stating the...
|
by: ryan.mclean |
last post by:
Hi all, first, let me preface this by saying that I am very new to sql
server, coming from oracle.
Here is my problem: I would like to have a case statement (similar to
decode in oracle) that will test a query for a null value. Here is my
statement:
SELECT
CASE
(SELECT MAX(SEQ) + 1
|
by: rAinDeEr |
last post by:
Hi,
I have a table with 2 columns
** CREATE TABLE test (emp_num DECIMAL(7) NOT NULL,emp_name CHAR(10) NOT
NULL) and i have inserted a number of records.
** Now, I want to insert a new record (3232,'Raindeer') based on the
condition that the
|
by: santoshsri |
last post by:
I wish to write a like statement within CASE statement .. Can it be possible , because I am getting error whenever I am using Like in CASE statement.The SQL is something like this
Select
CASE CBPQTN_BOOK_STAT
WHEN '22' THEN 'Declined'
WHEN '21' THEN 'Withdrawn'
WHEN '00' THEN 'Quoted'
WHEN '23' THEN 'Quoted'
WHEN '24' THEN 'Quoted'
WHEN '27' THEN 'Quoted'
WHEN 'Y0' THEN 'Quoted'
| |
by: priyanka2203 |
last post by:
Hi guys,
I have a doubt regarding the CASE statement. It might sound silly, but me being new to DB2, it is kind of a genuine doubt. Try helping me with this..
When we use a case statement (simple-case-statement-when-clause), in this -
the value of the expression prior to the first WHEN keyword is tested for equality with the value of each expression that follows the WHEN keyword. Right?
Then if the search condition is true, the THEN...
|
by: rshivaraman |
last post by:
hi All :
I have an insert statement which reads
INSERT Into TableA (Col1)
SELECT CASE WHEN Col1 LIKE '%%' THEN 999999 ELSE Col1 END AS
Col1,
FROM TableB
|
by: bpw22az |
last post by:
I am currently in the process of setting up an asp page that sends an inquiring student an email regarding his/her application status. The student enters his/her email address on a web page, the address is associated with the correspponding record in a sql database table, and an email is generated and sent to them based on app status. I am focusing on the "Incomplete" portion which will list all null fields from the table in the email. Using...
|
by: Satya |
last post by:
Hi everyone,
This is the first time iam posting excuse me if iam making any
mistake. My question is iam using a switch case statement in which i
have around 100 case statements to compare. so just curious to find
out is it effective to use this method?? or is there is any other
alternative method present so that execution time and code size can be
reduced??
Thanks in advance.
|
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: jinu1996 |
last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth.
The Art of Business Website Design
Your website is...
| |
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: conductexam |
last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one.
At the time of converting from word file to html my equations which are in the word document file was convert into image.
Globals.ThisAddIn.Application.ActiveDocument.Select();...
|
by: TSSRALBI |
last post by:
Hello
I'm a network technician in training and I need your help.
I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs.
The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols.
I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
|
by: adsilva |
last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
| |
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...
| |