473,320 Members | 2,052 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,320 software developers and data experts.

User defined variables question

Hi,

Im trying to write an SQL file which contains SQL queries which are to
be run individually one after the other. Im using user defined
variables so that I can save time on having to manually insert
constant values.

Hope this makes sense:

SET @sequence := SELECT COUNT(*) FROM tracks WHERE cd_id = 12;
INSERT INTO tracks (song, artist, sequence, cd_id) SET ('Fools Gold',
'Stone Roses', @sequence, 12);

Basically here Im trying to SET the value of $sequence based on the
result of the select statement. So when I first run the two queries
@sequence will have a zero value, the next time it will count the
tracks table and will now return a value of 1, then 2, 3,4 etc. Each
time I will replace the values of the INSERT query but the SET SELECT
query will remain. The SELECT statement runs fine on its own but
obviously Im either trying to do something that is not possible with
the user-defined variables or more likely Ive got the query wrong.
Anyway, could someone please point me in the correct direction, much
appreciated. Thanks

Burnsy

Jul 11 '07 #1
1 2539
Its cool, figured it out:

SELECT @sequence := COUNT(track_id) FROM tracks WHERE cd_id = 12;

or for whole values:

SELECT @sequence := COUNT(track_id)+1 FROM tracks WHERE cd_id = 12;

Cheers

Jul 11 '07 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

7
by: Jon Grieve | last post by:
Having come to PHP from another CGI, there's one thing I really miss... The previous tool used was Witango, which had one major difference: the interpreter ran as a service/daemon. One benefit...
1
by: user | last post by:
Sorry this must be really trivial, but I am new to Python... suppose I defined a=5 b=7 c=9 is there a command like usr_vars()
2
by: Steve D | last post by:
I've looked all over but can't find a solid answer. I've got a function that runs from a View and when the function runs the first time it is calculating a Temperature for a group of Formulas. ...
13
by: dawatson833 | last post by:
I have several stored procedures with parameters that are defined with user defined data types. The time it takes to run the procedures can take 10 - 50 seconds depending on the procedure. If I...
4
by: Sameer Deshpande | last post by:
How do I create and return user defined data types in DB2. F.ex In Oracle I can create a user define datatype and return this data type from stored function. How can I do the same in DB2? ...
3
by: Dan Nash | last post by:
Hi I'm new to C#, moving from ASP, and slightly confused so bear with me! Basically I've got 4 pages, each of which runs the same user control (some header information). I want to be able to...
9
by: jsale | last post by:
Hello, I am having a problem with multiple users using my asp.net application - namely that if each user clicks save at the same time, some, or all, of the users crash out. Do I need to do...
3
by: chreo | last post by:
I have user-defined function in MSSQL which returns Table (with 10 columns) (sorry for Polish names) CREATE FUNCTION PACZKI_Z_AKCJI (@AKCJA_ID int) RETURNS TABLE RETURN SELECT TOP 100...
4
by: Rui.Hu719 | last post by:
Hi, All: I read the following passage from a book: "There are three exceptions to the rule that headers should not contain definitions: classes, const objects whose value is known at compile...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.