Question: Sometimes an SQL statement needs to use more than two databases, so how do you write SQL statements?
Answer: Use DatabaseName. TableName to visit the table on it.
Example:
2. Matching Query
Question: I want to implement a string matching query, what should I do?
Answer: With like, see the online Help for SQLServer2000. Enter "Like" in the index with very detailed descriptions and examples.
Add: This problem is proposed because the author in the query all fabrics contain the text "50% Cotton" when the lead, because it contains one or more special wildcard "%". When the author writes the following statement:
Execution result is (not real data):
The correct wording is:
Or:
3. Cross-Data report
Question: How do I get cross-data query results?
Answer: See SQLServer2000 online Help for more details. Enter the crosstab report in the index to view.
Add: In the program, you can use distinct or group to select all the cross data columns satisfying the condition, then construct the cross data query statement; If you want a write stored procedure to return a data result set, you can use a cursor, generate a query string, and then use the system stored procedure to sp_ ExecuteSQL executes the string.
4, is the tail of the space caused the curse
Question: When querying data with like, I feel that I write the SQL statement is no problem, that is, do not get the data you want, what is going on?
Answer:
A. The use of string comparisons that contain char (fixed length) and varchar (variable length) data patterns may not be possible through like comparisons because of the way data is stored. It is important to understand how each data type is stored and what causes like comparisons to fail.
B. Trailing spaces make sense when you use like for Unicode data (nchar or nvarchar data types). For non-Unicode data, however, trailing spaces are meaningless.
Add: Ask the reader to do some experiments below to personally feel the difference.
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.