0 голосов
спросил от в категории SQL
Никто не может решить вашу проблему по нескольким причинам, например: у нас нет доступа к вашим данным, ваш запрос sql нечитабелен и, следовательно, уродлив! Извините ...

По-моему, вы используете слишком много подзапросов ( SELECT )! Смотрите:
SELECT     last_name                             FROM          dbo.l_person                             WHERE      (person_key = cw.requested_by_person_key)) AS [Referring physician last name],                           (SELECT     RTRIM(address_line1 + ' ' + ISNULL(address_line2, '')) AS Expr1                             FROM          dbo.l_person_address                             WHERE      (person_address_key = cw.requested_by_address_key)) AS [Referring address line 1 + 2  (location seen for selected accession)],                           (SELECT     RTRIM(city + ', ' + ISNULL(state, '') + ' ' + ISNULL(zipcode, '')) AS Expr1                             FROM          dbo.l_person_address AS l_person_address_3                             WHERE      (person_address_key = cw.requested_by_address_key)) AS [Referrring city, state, zip],                           (SELECT     phone_number                             FROM          dbo.l_person_address AS l_person_address_2                             WHERE      (person_address_key = cw.requested_by_address_key)) AS [Referring phone], ISNULL                           ((SELECT     fax_number                               FROM         dbo.l_person_address AS l_person_address_1                               WHERE     (person_address_key = cw.requested_by_address_key)), '') AS [Referring fax], ISNULL                           ((SELECT     dbo.c_GetNameFromUserID(performed_by_user_id) AS Expr1                               FROM         dbo.c_study                               WHERE     (study_key = cw.study_key)), '') AS [Technologist full name (first name, last name, suffix)], pr.description AS [Practice name],                        s.description AS [Location name], RTRIM(ISNULL(s.address_line1, '') + ' ' + ISNULL(s.address_line2, '')) AS [Location address line 1 + 2], ISNULL(s.city, '')                        + ', ' + ISNULL(s.state, '') + ' ' + ISNULL(s.zipcode, '') AS [Location address city, state, zip], s.main_phone_number AS LocationMainPhone,                        s.main_fax_number AS LocationMainfax, CASE WHEN                           (SELECT     cf.contents                             FROM          l_config_file cf                             WHERE      cf.file_name = s.logo_file_name) IS NULL THEN                           (SELECT     cf.contents                             FROM          l_config_file cf, l_practice pr                             WHERE      cf.file_name = pr.logo_file_name AND pr.practice_code = s.practice_code) ELSE                           (SELECT


Вы видите, сколько SELECT операторов существует? Я не могу даже сосчитать их!

Примечание: объединение таблиц с помощью инструкции WHERE очень устарело (устаревшая) практика! Вы должны использовать
SELECT     last_name                             FROM          dbo.l_person                             WHERE      (person_key = cw.requested_by_person_key)) AS [Referring physician last name],                           (SELECT     RTRIM(address_line1 + ' ' + ISNULL(address_line2, '')) AS Expr1                             FROM          dbo.l_person_address                             WHERE      (person_address_key = cw.requested_by_address_key)) AS [Referring address line 1 + 2  (location seen for selected accession)],                           (SELECT     RTRIM(city + ', ' + ISNULL(state, '') + ' ' + ISNULL(zipcode, '')) AS Expr1                             FROM          dbo.l_person_address AS l_person_address_3                             WHERE      (person_address_key = cw.requested_by_address_key)) AS [Referrring city, state, zip],                           (SELECT     phone_number                             FROM          dbo.l_person_address AS l_person_address_2                             WHERE      (person_address_key = cw.requested_by_address_key)) AS [Referring phone], ISNULL                           ((SELECT     fax_number                               FROM         dbo.l_person_address AS l_person_address_1                               WHERE     (person_address_key = cw.requested_by_address_key)), '') AS [Referring fax], ISNULL                           ((SELECT     dbo.c_GetNameFromUserID(performed_by_user_id) AS Expr1                               FROM         dbo.c_study                               WHERE     (study_key = cw.study_key)), '') AS [Technologist full name (first name, last name, suffix)], pr.description AS [Practice name],                        s.description AS [Location name], RTRIM(ISNULL(s.address_line1, '') + ' ' + ISNULL(s.address_line2, '')) AS [Location address line 1 + 2], ISNULL(s.city, '')                        + ', ' + ISNULL(s.state, '') + ' ' + ISNULL(s.zipcode, '') AS [Location address city, state, zip], s.main_phone_number AS LocationMainPhone,                        s.main_fax_number AS LocationMainfax, CASE WHEN                           (SELECT     cf.contents                             FROM          l_config_file cf                             WHERE      cf.file_name = s.logo_file_name) IS NULL THEN                           (SELECT     cf.contents                             FROM          l_config_file cf, l_practice pr                             WHERE      cf.file_name = pr.logo_file_name AND pr.practice_code = s.practice_code) ELSE                           (SELECT
# [#<a href="https://msdn.microsoft.com/en-us/library/ee391

Пожалуйста, войдите или зарегистрируйтесь чтобы ответить на этот вопрос.

Категории

Добро пожаловать на сайт DraftingCode Q&A, где вы можете задавать вопросы и получать ответы от других членов сообщества.

Связанных вопросов не найдено

...