I've made a fiddle in SQL fiddle and am trying to display a list of numbers 1-99. I also want the numbers to be replaced with text if certain conditions are met. I have implemented the conditions but cannot input text since the column is an INT field. I have tried using CAST prior to the conditions but this only caused SQL fiddle to crash. I also tried changing the whole column to VARCHAR but I encountered the same result.
Any help is appreciated! The link to the fiddle is below.
http://sqlfiddle.com/#!18/691f2/1
EDITWORKING CODE
CREATE TABLE numbers(
numbers int
);
DECLARE @start as int
SET @start = 1
DECLARE @plus as int
SET @plus = 1
DECLARE @end as int
SET @end = 99
BEGIN TRANSACTION
WHILE (@start <= @end)
BEGIN INSERT INTO numbers
values (@start) SET @start += @plus
END COMMIT TRANSACTION;
UPDATE numbers
SET numbers = '3737'
WHERE numbers%3 = 0 AND numbers%7 = 0;
UPDATE numbers
SET numbers = '3333'
WHERE numbers%3 = 0;
UPDATE numbers
SET numbers = '7777'
WHERE numbers%7 = 0;
SELECT (CASE numbers
WHEN 3333 THEN 'Open'
WHEN 7777 THEN 'Source'
WHEN 3737 THEN 'OpenSource'
ELSE CAST(numbers as VARCHAR)
END) AS Numbers
FROM numbers;
What if I made two columns, how would I go about merging them?
If you want to merge the values of an int
column and a varchar
column into one column, you have to cast the int
as varchar
, since string values can't be cast as int
.