]+ ', [' [emailprotected]+ '],[' [emailprotected]+ '] ' + ' from [' [email protected]+ ']) p PIVOT (SUM ([' [emailprotected]+ ']) for [' [emailprotected]+ '] in (' + @sql_col + ')) as Pvt Where Pvt.hx_fzone is not null for ORDER by ' [Emailprotected]--print (@sql_str) EXEC (@sql_str) drop table #t_estimateamo Untreasondrop Table #t_ Estimateamountreasontotalend---------------------------------------------------------------------------SELECT @ end_dat
A simple SQL row-column Conversion
Author: eaglet
In database development, we often encounter the problem of column/column conversion, such as the following problems, three tables for departments, employees, and employees. We need to count a list similar to this.
Department No. Department name total formal employee tem
Symptom:
Today, when I used powerdesigner 16 to design a database, the exported SQL statement was executed in SQL Server, which was suddenly miserable, crazy, and even intended to commit suicide !!!
For an error like a question, see the following SQL statement:
Create Table DBO. t_call_note (ID Int Identity ( 100 , 1 ), Name
Today, in the garden, we see an example of a group by grouping multi-column statistics, and we'll share it with you:CREATE TABLE Tests (year datetime year to Year,type char (1), value int);ALTER TABLE tests ALTER COLOMN year INT;INSERT into tests values (2015,1,100);INSERT into tests values (2015,2,200);INSERT into tests values (2016,1,150);INSERT into tests valu
Label:Purpose: To merge multi-line values of the same condition into the same column. 1. Create a Test table: CREATE TABLE [dbo].[tb_01](
[SN] [nvarchar]( -)NULL,
[Step_name] [nvarchar]( -)NULL,
[sdate] [datetime] NULL
) on [PRIMARY] 2. Insert the test data: INSERT intoTb_01VALUES('V000001','FQC','2015-01
Label:Build table: CREATE TABLE Studentinfo ( Name varchar, subject varchar (+), score number (3,1)); Insert Record: INSERT into studentinfo values (' Zhang San ', ' language ', 69); INSERT into studentinfo values (' Zhang San ', ' math ', 70); INSERT into studentinfo values (' John Doe ', ' language ', 20); The records inside are: The result we want is: The following SQL can be implemented: Select a name, Max (A1) language, Max (A2) Math from ( Se
Tags: des style blog http io cti ar htmlHow to specify a description for a column when creating a table with an SQL statement. The sp_addextendedproperty is used primarily for this stored procedure.Grammar
sp_addextendedproperty[@name =] {' property_name '}[, [@value =] {' V Alue '} [, [@level0type =] {' Level0_object_type '} , [@ Level0name =] {' Level0_object_name '} [, [@lev
The Code is as follows:EXEC sp_rename 'table name. [original column name] ', 'new column name', 'column'Transact-SQL referenceSp_renameChange the name of the user-created object (such as a table, column, or user-defined data type) in the current database.SyntaxSp_rename [@ objname =] 'object _ name ',[@ Newname =] 'new
Reading directory
I. Preface
Ii. First Thought
Iii. Second Thought
4. The third thought
I. Preface
In some of our projects, we often encounter the problem of converting rows into columns. Now let's discuss how we can convert Table 1 to table 2 format.
Figure 1
Figure 2
Ii. First Thought
As you can see, table 2 columns are converted from the data rows in table 1, and only the name column is the
SQL queries the Table Name and description table field (column) Information in the MySql database, sqlmysql
The following describes how to use an SQL query statement to obtain the name of a table in a Mysql database, table description, field ID, field name, data type, length, precision, whether it can be null, default
Tags: img different val sql2005 blog int section bar GESRequirements: By grouping, the contents of multiple records are combined into one, the effect is as follows: Database Example: CREATE TABLE [T2] ([NID] [bigint] null,[district] [nvarchar] (255) null,[town] [nvarchar] (255) NULL);
INSERT into T2 values (1, ' Huai area ', ' Cao Lao Ji Zhen ');
INSERT into T2
Error Message
Description the server encountered an internal error () that prevented it from fulfilling This Request. exceptionorg. springframework. Web. util. nestedservletexception: Request Processing failed; Nested exception is org. springframework. JDBC. uncategorizedsqlexception: sqlmapclient operation; uncategorized sqlexception For SQL []; SQL State [ Null
Check whether the table exists
1. Use System View: SYS. Tables
Select name from SYS. tables where name = 'tablaname' and type = 'U'
Type = 'U' is used to exclude stored procedures, views, and system tables. It refers to the user table user_table.
2. Use the System View: sysobjectsSelect * From sysobjects where id = object_id ('usersubsyscenthistory _ null') and xtype = 'U'
Xtype = 'U' is used to exclude stored procedures, views, and system tables. It
The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion;
products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the
content of the page makes you feel confusing, please write us an email, we will handle the problem
within 5 days after receiving your email.
If you find any instances of plagiarism from the community, please send an email to:
info-contact@alibabacloud.com
and provide relevant evidence. A staff member will contact you within 5 working days.