How to create column in SQL query with custom text
@Strawberry wrote what is needed, it's only need to put
SELECT id,'my text error' as error,aa,bb,NULL AS cc, NULL AS dd
FROM test
WHERE aa=SomeRequirement AND
bb=SomeRequirement
And this will work job that i want.
How to add a user defined column with a single value to a SQL query
Like this:
SELECT PRODUCT_ID, ORDER_QUANTITY, 999 as USER_VALUE
FROM PRODUCT_TABLE
GROUP BY SALES_DAY
How to add custom text on both sides of a result of a select query
Do you mean something like this?
select '<iframe>'|| site_domain||'</iframe>'
from site where status = "active"
How can I add text to SQL Column
You can simply update column using statement
update TableName set ColumnName = 'www.mypizza.com/' + ColumnName
SQL - How to add a custom text at the beginng of a row
There are a couple of ways to do this.
Move the Select to the outside:
DECLARE @Option AS TABLE ([Name] varchar(30))
INSERT INTO @Option([Name])
VALUES ('Option1'), ('Option2'), ('Option3')
SELECT 'Please Select : ' + LEFT(Options, LEN(Options) - 2)
FROM
(
SELECT Name + ' - '
FROM @Option
ORDER BY Name
FOR XML PATH('')
) o (Options)
There is also the COALESCE way:
DECLARE @Option AS TABLE ([Name] varchar(30))
INSERT INTO @Option([Name])
VALUES ('Option1'), ('Option2'), ('Option3')
DECLARE @Names VARCHAR(8000)
SELECT @Names = COALESCE(@Names + ' - ', '') + Name
FROM @Option
SELECT 'Please Select : ' + @Names
Can I use SQL to display custom text that is based on the column value?
A fun way to do this uses elt()
:
select elt(value + 1, 'no', 'yes')
elt()
returns the nth string based on the first argument.
How can I add text to my column's select statement
Just use cast
or convert
to convert it all to varchar
for instance.
SELECT 'Please try after' + CAST((1328724983-time)/60/60 as varchar(80)) AS status
FROM voting
WHERE account = 'ThElitEyeS' AND vid = 1;
See the MSDN on Cast / Convert
Based on your comments you can do:
SELECT 'Please try again after' + CAST(MyColForHours as varchar(25)) + ' hours', AnyOtherColumns FROM Table
Using CASE to create new column based on specific text in a string column
You had some syntax issues:
1st issue was: CASE (WHEN
2nd issue was: ELSE WHEN
This should run fine now:
SELECT DISTINCT
R.[Column1] AS Person,
SUM(CASE
WHEN R.[Event] = 'Event1'
THEN 1
ELSE NULL
END) AS Event1,
(CASE
WHEN L.[Column2] LIKE '%String1%'
THEN 'String1'
WHEN L.[Column2] LIKE '%String2%'
THEN 'String2'
WHEN L.[Column2] LIKE '%String3%'
THEN 'String3'
ELSE NULL
END) AS NewColumn
FROM [Database1].[dbo].[Table1] R
LEFT JOIN [Database1].[dbo].[Table2] L ON R.[UniqueIdentifier] = L.[UniqueIdentifier]
WHERE L.[Column2] LIKE '%String1%'
OR L.[Column2] LIKE '%String2%'
OR L.[Column2] LIKE '%String3%'
GROUP BY R.[Column1],
L.[Column2]
ORDER BY R.[Event1] DESC;
How to Add Long Text Column to Access Table Via Query
Found the answer shortly after posting the question. Using the query
ALTER TABLE TestTable ADD Description LONGTEXT;
creates a new column of type "Long Text". It should be noted that a character count was not necessary for this type.
Related Topics
Insert If Not Exists Else Update
How to Select the Last Record of a Table in SQL
Postgresql Delete Multiple Rows from Multiple Tables
Sql Server: Check If Variable Is Null and Then Assign Statement for Where Clause
1052: Column 'Id' in Field List Is Ambiguous
How to Select Rows With Only Numeric Characters in Oracle SQL
Calculating Percent Change Between Two Rows
How to Calculate Date Difference in Postgresql
Run a Join Statement That Excludes Duplicate Rows
Jsonb Array Contains Like or and and Operators
Adding $ Dollar Sign on My Total Cost in SQL Server
Force a Value of 0 for Non-Existing Value
Sql Take Just the Numeric Values from a Varchar
How to Select an Empty Result Set
Mysql - Operand Should Contain 1 Column(S)
Subtract Two Columns from Two Tables With Group By