SQLServer FAQ response
Copyright © ASHUIXU Reprint, please stay intact and indicate
SQL statement part
1, SQL statement across more than two databases
Question: Sometimes a SQL statement needs to use more than two databases, how do such a SQL statement write?
Answer: Use DatabaseName..tableName to access the table.
Example:
2, matching query
Question: I want to realize the matching query of the string, what should I do?
Solution: Use like, see the online help of SQLServer2000. Enter "Like" in the index and have a very detailed description and examples.
Supplement: This problem is proposed because the author is taken out when querying all fabrics "50% pure cotton" because it contains one or more special wildcard "%". When the author writes the following statement:
The result is (non-true data):
The correct way of writing is:
or:
3,
Cross data report
Question: How do I get cross data query results?
Answer: For more detailed content, please refer to SQLServer2000 online help. Enter "Cross Data Report" in the index to view.
Supplement: You can select all the cross-data columns that meet the conditions in the program, and then construct a cross-data query statement; if you want a write storage process to return a data result set, you can use a cursor to generate a query string. Then, then execute the string with the system stored procedure sp_executesql.
4, all the tail spaces
Question: When using Like query data, I feel that I have written the SQL statement, I can't get the data you want, what is going on?
answer:
A. Due to the cause of the data storage method, comparison with a string containing the char (fixed length) and varchar (variable length) data mode may not be compared. It is important to learn about the storage method of each data type and cause the LIKE comparison failure.
B. When using Like when using Like for Unicode data (Nchar or NVARCHAR data type), it makes sense. But for non-Unicode data, there is no significant difference between trailing spaces.
Supplement: Please read the readers to do some tests below, and feel the differences in person.
(Untrained ...)