Is it possible to do something like this? Essentially I want to cast a int into a string and used the string on a join. Pay attention to the %t1.id%
select t2.*
from t1
join t2 on t2.url='site.com/path/%t1.id%/more'
where t1.id > 9000
You could use CONCAT, and the numeric argument of it is converted to its equivalent binary string form.
select t2.*
from t1 join t2
on t2.url=CONCAT('site.com/path/%', t1.id, '%/more') where t1.id > 9000
You can do this:
select t2.*
from t1
join t2 on t2.url = 'site.com/path/' + CAST(t1.id AS VARCHAR(10)) + '/more'
where t1.id > 9000
Pay attention to CAST(t1.id AS VARCHAR(10)).
I've ended here while doing some research, not exactly for this reason, but I love this kind of "puzzles" :-)
Here's my version of a random vehicle plate generator, it's inspired from European plates (inspired - not an exact copy!).
-- (AA) (BBCCCC) ['YY]
-- \1 \2 \3 \4
--
-- 1 = year related series
-- 2 = Random MD5 string
-- 3 = Timestamp based MD5 string (uniqueness)
-- 4 = year of registration (shared with part 1)
SELECT
UPPER(
CONCAT(
LEFT(
TO_BASE64(
@rndVehicleYear:= RIGHT(
CONVERT(
floor(rand() * (year(current_date) - (@minYear := 1980)) + @minYear),
CHAR
),
2
)
),
2
),
SPACE(1),
LEFT(MD5('ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789'), 2),
LEFT(MD5(unix_timestamp()), 4),
SPACE(2),
CONCAT('`', @rndVehicleYear)
)
)
AS RandomVehiclePlate;
Explained in simple words, a random Year is selected between 1980 and the current one: it will be used as a seed to create the first 2 Chars, but also in clear text, at the end of the plate.
Two more chars are random MD5, and the last 4 ensure that the plate is unique (that's my goal, at least), by generating chars on the currrent timestamp.
You can remove @rndVehicleYear := RIGHT( <- this and keep the full year instead of the last two numbers.
Cheers!