Quantcast
Channel: Transact-SQL forum
Viewing all articles
Browse latest Browse all 23857

Query Correct But Unable to execute might be due to length limit for inner query.

$
0
0

Following it the dynamic query that is been generated in one of my operation, Now the issue is that its generating error like 

Also need to look at the error

 

Timestamp: 2014-04-30 21:22:41.160

Message: Unclosed quotation mark after the character string '13fa4efe-'.

Incorrect syntax near '13fa4efe-'.

 On Investigating we found that the inner execute is reaching to the limit and when it is executed from the outer execute.

exec sp_executesql N'IF OBJECT_ID(''tempdb..#attributeLocationUserTemp'', ''U'') IS NOT NULL  
                                                                DROP TABLE #attributeLocationUserTemp
                                                                CREATE TABLE #attributeLocationUserTemp
                                                                (  
	                                                                ka_user_guid nvarchar(36),
	                                                                tenant_id int,
	                                                                system_string_object_guid nvarchar(36),
	                                                                name varchar(250),
	                                                                system_string_object_type_id nvarchar(36),
                                                                )  

                                                                INSERT INTO #attributeLocationUserTemp 
                                                                (ka_user_guid,tenant_id,system_string_object_guid,name,system_string_object_type_id)
                                                                SELECT 
	                                                                kusl.ka_user_guid,
	                                                                kusl.tenant_id,
	                                                                sso.system_string_object_guid,
	                                                                sso.name,
	                                                                sso.system_string_object_type_id
                                                                FROM
	                                                                KA_USER_SYSTEM_LIST kusl
                                                                INNER JOIN
	                                                                SYSTEM_STRING_OBJECT sso
	                                                                ON
	                                                                kusl.system_string_object_guid = sso.system_string_object_guid
                                                                WHERE sso.system_string_object_type_id = 3 DECLARE @LCUserCols AS VARCHAR(MAX)  SET @LCUserCols = ''[25f2a257-a326-4e63-a6e5-643520d140be],[4b2a71a8-4296-4545-9c8a-a37829c593ff],[56197e46-f1f6-49ff-bc89-5a80ad49fcc2],[9bbc4c79-dc8d-4d84-9ed3-78fa67c28625],[52f1c056-f7c6-4a90-aca8-228563d70f14],[b5702a9e-6abf-46b3-a616-d7cdf5243358],[00d211ea-ca2a-465b-8177-f5efcf55673d],[9ad0b77b-dc9a-48a8-9eec-20c22fef6e63],[c4e26f79-b5d4-4644-adc1-34685a2f32a3],[561f91bd-2599-4fe6-a27d-c3a2155c412e],[65086c9b-aebb-4b7c-83cb-103a6256f4c9],[8c5785c1-8c5e-48cb-8b8c-67b9c2365347],[9a4c1a03-d8e3-40c0-b3f2-131a037c468f],[d240e4f7-43f1-4bbf-8257-08c26fdb49d8],[470f9ed7-96fa-4373-8cae-82e5278bf698],[f0e0157e-e8dd-444c-81ee-aef96ee63352],[b503d7f6-68e8-4f1a-8881-5fd9e586ed2c],[1b8db7f0-c69f-4ae9-9704-89772a97a1b2],[c26f0b31-859d-4845-9ef0-3c70e486d0ad],[f46c5628-ddcf-4c22-87ef-c846f89187aa],[3dd91217-b27f-4c4b-ab6b-da399b4bad63],[e477bf4a-408f-498e-bb9f-92cf7255581e],[1d0503c8-88a8-4315-981d-7bbde9b2ce16],[8cee67c9-8aae-4ed1-a8c9-9422a55aba90],[b4281cc7-c634-456e-a1c4-254ce25f26e6],[61db2055-3acd-4f2c-b028-b488cabec48f],[4fd344f7-45aa-4e9e-9b28-2a54c7d4b793],[fed9681b-7db5-4588-99c2-fdd676f2b283],[8950bb57-2324-4b1f-9e21-d76eb039fd33],[e7b9a419-fd95-47a4-930e-43fc8286ad96],[c7b659d2-b95a-4bb6-acdd-250cbe33d22d],[5c6584c1-e4dd-42c1-9589-fe9170e24026]'' IF OBJECT_ID(''tempdb..#customAttributeUserTempTable '', ''U'') IS NOT NULL  
                                                                DROP TABLE #customAttributeUserTempTable  
                                                                CREATE TABLE #customAttributeUserTempTable 
                                                                (  
                                                                    ka_user_guid nvarchar(36),
                                                                    tenant_id int,
                                                                    custom_attribute_group_guid nvarchar(36),
                                                                    name nvarchar(250),
                                                                    custom_attribute_guid nvarchar(36),
                                                                    value varchar(50)
                                                                )  INSERT INTO #customAttributeUserTempTable 
                                                                    (ka_user_guid,tenant_id,custom_attribute_guid,value,custom_attribute_group_guid,name)
                                                                                                                                    SELECT kuca.ka_user_guid,kuca.tenant_id,kuca.custom_attribute_guid,kuca.value,ca.custom_attribute_group_guid, CASE WHEN ca.identifier IS NULL  THEN ca.name ELSE ca.identifier END  FROM KA_User_Custom_Attribute kuca LEFT OUTER JOIN CUSTOM_ATTRIBUTE ca ON ca.custom_attribute_guid=kuca.custom_attribute_guid WHERE kuca.custom_attribute_guid IN ( ''0163a162-e091-40aa-9603-4ce6cbef2dc8'',''39d80026-378f-48d7-9be3-7a91a2f5bec4'',''75a74052-a9c9-464d-bdf3-5d43f668d35d'',''a294d286-07e9-4981-a004-c17f21d08c55'',''d5dcc00e-4376-48f6-b76f-6d9c80697b62'',''479e87aa-077d-411c-8d84-aedd919905dc'',''a75e4c79-7b57-4360-9238-8e29e835e2e9'',''2c08b4d7-b338-46c6-b26a-6e88a6020aea'',''4713291e-46f5-4702-8162-035bb0c3cc07'',''a77ab0db-ccff-46ed-81f2-25b8c2b4ee5d'',''724eced1-068a-4082-b312-723c7d2c80bc'',''93956925-2245-4d21-ba44-355101dfd538'',''204d07dc-8c1c-4e2d-bd12-80bf4c2c82db'',''1c248164-b661-4abb-bed8-2a3464933a54'',''ef487c55-e5da-4cdf-82d5-0af3062321c5'',''8320f3f2-cca4-4c33-8f23-7bd219adef51'',''0b67918c-f97c-4c04-84a2-28b2e214dcd7'',''255c2db9-d4c0-4c75-97b4-aa0122f1281c'',''b616cee2-1057-4eb6-b020-c23687a522cd'',''1f6666ff-feaf-48a7-9a8f-cff370ebfa73'',''510f8cc7-cc03-464e-87ea-f1aa6196111e'',''e837803a-2c27-4c48-a7b5-46b4b8e25b08'',''f97f0fc3-2d26-4d69-96ce-4567f9f4e827'',''e508f57e-20b2-484d-9b0b-e6893a0e40b3'',''e1934c59-123a-4137-a699-8b017bb9086b'',''fe4469da-2925-4c15-bac7-967bddad0863'',''a5bb8707-9e70-4b86-be88-627c3bca6b7a'',''27dc4b00-5e32-498e-ae33-0860b2149090'',''45dc32ae-b946-489e-9de4-4e64fb14200d'',''60f98c82-e267-4dc4-9639-c713f2eec7d3'',''358bf953-1e66-4401-8871-8f9aeaad8760'',''06b31cd1-db1d-46cb-8f0c-07d044b3baac'',''66e071d7-97d7-4e74-bf82-a5aae0cb1c65'',''48c26c9d-0e45-41f6-9c31-82dbd1412f50'',''6acbb738-4641-4720-a26a-f5dfe137b0ef'',''4c056fa2-5752-467c-b8fe-1e1b01159f53'',''409c7551-f5e6-447b-8342-31c0c1d84e35'',''9622037b-2a2a-456e-b964-7d0af1b16546'') DECLARE @userCols AS VARCHAR(MAX),  @AttributeUserCols AS VARCHAR(MAX)  SET @userCols = ''[0163a162-e091-40aa-9603-4ce6cbef2dc8],[39d80026-378f-48d7-9be3-7a91a2f5bec4],[75a74052-a9c9-464d-bdf3-5d43f668d35d],[a294d286-07e9-4981-a004-c17f21d08c55],[d5dcc00e-4376-48f6-b76f-6d9c80697b62],[479e87aa-077d-411c-8d84-aedd919905dc],[a75e4c79-7b57-4360-9238-8e29e835e2e9],[2c08b4d7-b338-46c6-b26a-6e88a6020aea],[4713291e-46f5-4702-8162-035bb0c3cc07],[a77ab0db-ccff-46ed-81f2-25b8c2b4ee5d],[724eced1-068a-4082-b312-723c7d2c80bc],[93956925-2245-4d21-ba44-355101dfd538],[204d07dc-8c1c-4e2d-bd12-80bf4c2c82db],[1c248164-b661-4abb-bed8-2a3464933a54],[ef487c55-e5da-4cdf-82d5-0af3062321c5],[8320f3f2-cca4-4c33-8f23-7bd219adef51],[0b67918c-f97c-4c04-84a2-28b2e214dcd7],[255c2db9-d4c0-4c75-97b4-aa0122f1281c],[b616cee2-1057-4eb6-b020-c23687a522cd],[1f6666ff-feaf-48a7-9a8f-cff370ebfa73],[510f8cc7-cc03-464e-87ea-f1aa6196111e],[e837803a-2c27-4c48-a7b5-46b4b8e25b08],[f97f0fc3-2d26-4d69-96ce-4567f9f4e827],[e508f57e-20b2-484d-9b0b-e6893a0e40b3],[e1934c59-123a-4137-a699-8b017bb9086b],[fe4469da-2925-4c15-bac7-967bddad0863],[a5bb8707-9e70-4b86-be88-627c3bca6b7a],[27dc4b00-5e32-498e-ae33-0860b2149090],[45dc32ae-b946-489e-9de4-4e64fb14200d],[60f98c82-e267-4dc4-9639-c713f2eec7d3],[358bf953-1e66-4401-8871-8f9aeaad8760],[06b31cd1-db1d-46cb-8f0c-07d044b3baac],[66e071d7-97d7-4e74-bf82-a5aae0cb1c65],[48c26c9d-0e45-41f6-9c31-82dbd1412f50],[6acbb738-4641-4720-a26a-f5dfe137b0ef],[4c056fa2-5752-467c-b8fe-1e1b01159f53],[409c7551-f5e6-447b-8342-31c0c1d84e35],[9622037b-2a2a-456e-b964-7d0af1b16546]'' SET @AttributeUserCols = ''[ 00000000-0000-0000-0000-000000000000] ''
 DECLARE @query AS VARCHAR(MAX) set @query = ''
 INSERT INTO ASSIGNMENT_DEFINITION_KA_USER (assignment_definition_guid, ka_user_guid, modfiied_date, modified_by, tenant_id ) SELECT DISTINCT ''''''+@assignmentDefinitionGuid+'''''', u.ka_user_guid,  
                            GETUTCDATE(),
                            ''''''+@modifiedBy+'''''', u.tenant_id
                             FROM KA_USER u                                
                                 LEFT OUTER JOIN
	                                                            (
		                                                            SELECT 
			                                                            temp.ka_user_guid as temp_lc_user_guid,
			                                                            temp.system_string_object_guid as sys_obj_guid
		                                                            from 
			                                                            #attributeLocationUserTemp temp
	                                                            ) as x pivot
	                                                            (
		                                                            min(sys_obj_guid)
		                                                            for sys_obj_guid in ('' + @LCUserCols + '')
	                                                            ) lcUser
	                                                            ON 
		                                                            u.ka_user_guid = temp_lc_user_guid LEFT OUTER JOIN ( SELECT temp.ka_user_guid as user_guid, temp.custom_attribute_guid as attribute_value FROM #customAttributeUserTempTable  temp  ) as x pivot ( min(attribute_value) for attribute_value in ('' + @userCols + '') ) p1 on u.ka_user_guid = user_guid  LEFT OUTER JOIN ( SELECT attributeTemp.ka_user_guid as attribute_user_guid, attributeTemp.value custom_attribute_value, attributeTemp.custom_attribute_guid as attribute_guid FROM #customAttributeUserTempTable  attributeTemp ) as x  pivot  ( max(custom_attribute_value)  for attribute_guid in ('' + @AttributeUserCols + '') ) p2 ON attribute_user_guid = u.ka_user_guid  WHERE 
                                 u.archived <> 1 
    AND 
    ((([25f2a257-a326-4e63-a6e5-643520d140be] =  ''''25f2a257-a326-4e63-a6e5-643520d140be'''' OR [4b2a71a8-4296-4545-9c8a-a37829c593ff] =  ''''4b2a71a8-4296-4545-9c8a-a37829c593ff'''' OR [56197e46-f1f6-49ff-bc89-5a80ad49fcc2] =  ''''56197e46-f1f6-49ff-bc89-5a80ad49fcc2'''' OR [9bbc4c79-dc8d-4d84-9ed3-78fa67c28625] =  ''''9bbc4c79-dc8d-4d84-9ed3-78fa67c28625'''' OR [52f1c056-f7c6-4a90-aca8-228563d70f14] =  ''''52f1c056-f7c6-4a90-aca8-228563d70f14'''' OR [b5702a9e-6abf-46b3-a616-d7cdf5243358] =  ''''b5702a9e-6abf-46b3-a616-d7cdf5243358'''' OR [00d211ea-ca2a-465b-8177-f5efcf55673d] =  ''''00d211ea-ca2a-465b-8177-f5efcf55673d'''' OR [9ad0b77b-dc9a-48a8-9eec-20c22fef6e63] =  ''''9ad0b77b-dc9a-48a8-9eec-20c22fef6e63'''' OR [c4e26f79-b5d4-4644-adc1-34685a2f32a3] =  ''''c4e26f79-b5d4-4644-adc1-34685a2f32a3'''' OR [561f91bd-2599-4fe6-a27d-c3a2155c412e] =  ''''561f91bd-2599-4fe6-a27d-c3a2155c412e'''' OR [65086c9b-aebb-4b7c-83cb-103a6256f4c9] =  ''''65086c9b-aebb-4b7c-83cb-103a6256f4c9'''' OR [8c5785c1-8c5e-48cb-8b8c-67b9c2365347] =  ''''8c5785c1-8c5e-48cb-8b8c-67b9c2365347'''' OR [9a4c1a03-d8e3-40c0-b3f2-131a037c468f] =  ''''9a4c1a03-d8e3-40c0-b3f2-131a037c468f'''' OR [d240e4f7-43f1-4bbf-8257-08c26fdb49d8] =  ''''d240e4f7-43f1-4bbf-8257-08c26fdb49d8'''' OR [470f9ed7-96fa-4373-8cae-82e5278bf698] =  ''''470f9ed7-96fa-4373-8cae-82e5278bf698'''' OR [f0e0157e-e8dd-444c-81ee-aef96ee63352] =  ''''f0e0157e-e8dd-444c-81ee-aef96ee63352'''' OR [b503d7f6-68e8-4f1a-8881-5fd9e586ed2c] =  ''''b503d7f6-68e8-4f1a-8881-5fd9e586ed2c'''' OR [1b8db7f0-c69f-4ae9-9704-89772a97a1b2] =  ''''1b8db7f0-c69f-4ae9-9704-89772a97a1b2'''' OR [c26f0b31-859d-4845-9ef0-3c70e486d0ad] =  ''''c26f0b31-859d-4845-9ef0-3c70e486d0ad'''' OR [f46c5628-ddcf-4c22-87ef-c846f89187aa] =  ''''f46c5628-ddcf-4c22-87ef-c846f89187aa'''' OR [3dd91217-b27f-4c4b-ab6b-da399b4bad63] =  ''''3dd91217-b27f-4c4b-ab6b-da399b4bad63'''' OR [e477bf4a-408f-498e-bb9f-92cf7255581e] =  ''''e477bf4a-408f-498e-bb9f-92cf7255581e'''' OR [1d0503c8-88a8-4315-981d-7bbde9b2ce16] =  ''''1d0503c8-88a8-4315-981d-7bbde9b2ce16'''' OR [8cee67c9-8aae-4ed1-a8c9-9422a55aba90] =  ''''8cee67c9-8aae-4ed1-a8c9-9422a55aba90'''' OR [b4281cc7-c634-456e-a1c4-254ce25f26e6] =  ''''b4281cc7-c634-456e-a1c4-254ce25f26e6'''' OR [61db2055-3acd-4f2c-b028-b488cabec48f] =  ''''61db2055-3acd-4f2c-b028-b488cabec48f'''' OR [4fd344f7-45aa-4e9e-9b28-2a54c7d4b793] =  ''''4fd344f7-45aa-4e9e-9b28-2a54c7d4b793'''' OR [fed9681b-7db5-4588-99c2-fdd676f2b283] =  ''''fed9681b-7db5-4588-99c2-fdd676f2b283'''' OR [8950bb57-2324-4b1f-9e21-d76eb039fd33] =  ''''8950bb57-2324-4b1f-9e21-d76eb039fd33'''' OR [e7b9a419-fd95-47a4-930e-43fc8286ad96] =  ''''e7b9a419-fd95-47a4-930e-43fc8286ad96'''' OR [c7b659d2-b95a-4bb6-acdd-250cbe33d22d] =  ''''c7b659d2-b95a-4bb6-acdd-250cbe33d22d'''' OR [5c6584c1-e4dd-42c1-9589-fe9170e24026] =  ''''5c6584c1-e4dd-42c1-9589-fe9170e24026'''') OR ([0163a162-e091-40aa-9603-4ce6cbef2dc8] =  ''''0163a162-e091-40aa-9603-4ce6cbef2dc8'''' OR [39d80026-378f-48d7-9be3-7a91a2f5bec4] =  ''''39d80026-378f-48d7-9be3-7a91a2f5bec4'''' OR [75a74052-a9c9-464d-bdf3-5d43f668d35d] =  ''''75a74052-a9c9-464d-bdf3-5d43f668d35d'''' OR [a294d286-07e9-4981-a004-c17f21d08c55] =  ''''a294d286-07e9-4981-a004-c17f21d08c55'''' OR [d5dcc00e-4376-48f6-b76f-6d9c80697b62] =  ''''d5dcc00e-4376-48f6-b76f-6d9c80697b62'''' OR [479e87aa-077d-411c-8d84-aedd919905dc] =  ''''479e87aa-077d-411c-8d84-aedd919905dc'''' OR [a75e4c79-7b57-4360-9238-8e29e835e2e9] =  ''''a75e4c79-7b57-4360-9238-8e29e835e2e9'''' OR [2c08b4d7-b338-46c6-b26a-6e88a6020aea] =  ''''2c08b4d7-b338-46c6-b26a-6e88a6020aea'''' OR [4713291e-46f5-4702-8162-035bb0c3cc07] =  ''''4713291e-46f5-4702-8162-035bb0c3cc07'''' OR [a77ab0db-ccff-46ed-81f2-25b8c2b4ee5d] =  ''''a77ab0db-ccff-46ed-81f2-25b8c2b4ee5d'''' OR [724eced1-068a-4082-b312-723c7d2c80bc] =  ''''724eced1-068a-4082-b312-723c7d2c80bc'''' OR [93956925-2245-4d21-ba44-355101dfd538] =  ''''93956925-2245-4d21-ba44-355101dfd538'''' OR [204d07dc-8c1c-4e2d-bd12-80bf4c2c82db] =  ''''204d07dc-8c1c-4e2d-bd12-80bf4c2c82db'''' OR [1c248164-b661-4abb-bed8-2a3464933a54] =  ''''1c248164-b661-4abb-bed8-2a3464933a54'''' OR [ef487c55-e5da-4cdf-82d5-0af3062321c5] =  ''''ef487c55-e5da-4cdf-82d5-0af3062321c5'''' OR [8320f3f2-cca4-4c33-8f23-7bd219adef51] =  ''''8320f3f2-cca4-4c33-8f23-7bd219adef51'''' OR [0b67918c-f97c-4c04-84a2-28b2e214dcd7] =  ''''0b67918c-f97c-4c04-84a2-28b2e214dcd7'''' OR [255c2db9-d4c0-4c75-97b4-aa0122f1281c] =  ''''255c2db9-d4c0-4c75-97b4-aa0122f1281c'''' OR [b616cee2-1057-4eb6-b020-c23687a522cd] =  ''''b616cee2-1057-4eb6-b020-c23687a522cd'''' OR [1f6666ff-feaf-48a7-9a8f-cff370ebfa73] =  ''''1f6666ff-feaf-48a7-9a8f-cff370ebfa73'''' OR [510f8cc7-cc03-464e-87ea-f1aa6196111e] =  ''''510f8cc7-cc03-464e-87ea-f1aa6196111e'''' OR [e837803a-2c27-4c48-a7b5-46b4b8e25b08] =  ''''e837803a-2c27-4c48-a7b5-46b4b8e25b08'''' OR [f97f0fc3-2d26-4d69-96ce-4567f9f4e827] =  ''''f97f0fc3-2d26-4d69-96ce-4567f9f4e827'''' OR [e508f57e-20b2-484d-9b0b-e6893a0e40b3] =  ''''e508f57e-20b2-484d-9b0b-e6893a0e40b3'''' OR [e1934c59-123a-4137-a699-8b017bb9086b] =  ''''e1934c59-123a-4137-a699-8b017bb9086b'''' OR [fe4469da-2925-4c15-bac7-967bddad0863] =  ''''fe4469da-2925-4c15-bac7-967bddad0863'''' OR [a5bb8707-9e70-4b86-be88-627c3bca6b7a] =  ''''a5bb8707-9e70-4b86-be88-627c3bca6b7a'''' OR [27dc4b00-5e32-498e-ae33-0860b2149090] =  ''''27dc4b00-5e32-498e-ae33-0860b2149090'''' OR [45dc32ae-b946-489e-9de4-4e64fb14200d] =  ''''45dc32ae-b946-489e-9de4-4e64fb14200d'''' OR [60f98c82-e267-4dc4-9639-c713f2eec7d3] =  ''''60f98c82-e267-4dc4-9639-c713f2eec7d3'''' OR [358bf953-1e66-4401-8871-8f9aeaad8760] =  ''''358bf953-1e66-4401-8871-8f9aeaad8760'''' OR [06b31cd1-db1d-46cb-8f0c-07d044b3baac] =  ''''06b31cd1-db1d-46cb-8f0c-07d044b3baac'''' OR [66e071d7-97d7-4e74-bf82-a5aae0cb1c65] =  ''''66e071d7-97d7-4e74-bf82-a5aae0cb1c65'''' OR [48c26c9d-0e45-41f6-9c31-82dbd1412f50] =  ''''48c26c9d-0e45-41f6-9c31-82dbd1412f50'''' OR [6acbb738-4641-4720-a26a-f5dfe137b0ef] =  ''''6acbb738-4641-4720-a26a-f5dfe137b0ef'''' OR [4c056fa2-5752-467c-b8fe-1e1b01159f53] =  ''''4c056fa2-5752-467c-b8fe-1e1b01159f53'''' OR 
[409c7551-f5e6-447b-8342-31c0c1d84e35] =  ''''409c7551-f5e6-447b-8342-31c0c1d84e35'''' OR [9622037b-2a2a-456e-b964-7d0af1b16546] =  ''''9622037b-2a2a-456e-b964-7d0af1b16546'''')) AND (u.active = 1))                              
                                '' execute(@query) ',N'@assignmentDefinitionGuid nvarchar(36),@modifiedBy nvarchar(22)',@assignmentDefinitionGuid=N'7c103785-82f5-44d6-a289-6f732ba5ec1b',@modifiedBy=N'Assignment Rule Engine'

Let me know any way to solve this issue. Its an dynamic query and when we are executing it without inner execute the it runs fine. 


Ankit Verma


Viewing all articles
Browse latest Browse all 23857

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>