PIVOT in SQL using row value as Column names [duplicate] - sql

This question already has answers here:
How to convert rows into columns in SQL Server?
(2 answers)
Convert Rows to columns using 'Pivot' in SQL Server
(9 answers)
SQL server : Convert rows into columns
(1 answer)
Convert rows to columns in SQL
(1 answer)
Closed 2 years ago.
I have a table, say Maintable like this.
I want to view this table like this:
How can this be achieved using dynamic SQL?

Related

How can I search a string in more than ten columns in SQL [duplicate]

This question already has answers here:
Checking if a string is found in one of multiple columns in mySQL
(6 answers)
Closed 1 year ago.
I want search a string in all 10 columns in a SQL table. How can I do it in SQL?
For example :
I have to search “Computer” word in all ten columns or all the columns in a single table .
You should use "OR" operator.
For Example:
SELECT * FROM Table
WHERE (col1 LIKE '%searchstring%') OR (col2 LIKE '%searchstring%') OR (col3 LIKE '%searchstring%')

How to handle a column named table in database table [duplicate]

This question already has answers here:
How to deal with SQL column names that look like SQL keywords?
(17 answers)
Syntax error due to using a reserved word as a table or column name in MySQL
(1 answer)
Are quotes around tables and columns in a MySQL query really necessary?
(4 answers)
Closed 2 years ago.
I am currently working with Joomla. I want to insert a new row into #__content_types table, but there is a column named table that is currently giving me errors.
How do I insert the data despite the name of the column 'table'?
INSERT INTO #__content_types(type_id, type_title, type_alias, table, field_mappings)
VALUES
('14','SVG Image','com_view_vv.form','{"special":{"dbtable":"#__table","key":"id","type": "Corecontent","prefix":"JTable","config":"array()"},"common":{"dbtable": "#__ucm_content","key":"ucm_id","type":"Corecontent","prefix":"JTable","config":"array()"}}', '{"common": {"core_content_item_id":"id","core_title":"name","core_alais": "alias"},"special":{"imptotal":"imptotal","impmade":"impmade","clicks": "clicks","clickurl": "clickurl","custombannercode":"custombannercode","cid":"cid","purchase_type": "purchase_type","track_impressions":"track_impressions","track_clicks":"track_clicks"}}');

is there a "Wildcard Except" function in MSSQL? [duplicate]

This question already has answers here:
SELECT * EXCEPT
(15 answers)
Exclude a column using SELECT * [except columnA] FROM tableA?
(47 answers)
Can you SELECT everything, but 1 or 2 fields, without writer's cramp?
(12 answers)
Closed 3 years ago.
Often I find myself wanting to insert all columns except the IDENTITY column into a table, or select all columns apart from one.
I wonder if there's something in SQL Server like:
SELECT * EXCEPT SomeColumn FROM SomeTable
?

Automatically prefix columns with the same name in a select [duplicate]

This question already has answers here:
Prefix all columns in T-SQL statement
(3 answers)
Prefix every column name with a specific string?
(1 answer)
How can I prefix all column names in a T-SQL function?
(2 answers)
Closed 3 years ago.
How could one easily select from tables that contain columns with the same name? Conflicting names in a CTE for example are not allowed. Is there a way to for example automatically rename all of the columns as TableName_ColumnName? Having to write out all of the columns just for this is very impractical.

How do I search the name of a table, knowing only one of the table's column name in SQL? [duplicate]

This question already has answers here:
Search an Oracle database for tables with specific column names?
(4 answers)
Closed 7 years ago.
I'm trying to find a table containing a column that I know the name to. Is there some way to do a table search using only the name of the column?
In oracle
select * from user_tab_columns where column_name= '';