Skip to main content

SLAM_query

Overview

This generalized query method provides access to all three APIs and file downloading through a single procedure. It delegates to the appropriate query procedure based on the @api parameter, making it a convenient choice when the API selection needs to be dynamic. @batch_size is only relevant to SOAP API and @pkchunksize is only relevant to Bulk v1 API.

Parameters

NameTypeDefaultDescription
@queryNVARCHARRequiredsObject name or SOQL query string. When just an sObject name is passed, queries all records & fields
@tableVARCHARRequiredTarget SQL table name for results
@apiNVARCHARRequiredAPI to use ('bulk', 'bulkv2', or 'soap')
@pkchunksizeINTNULLEnable PK chunking (Bulk v1 API only). If NULL, PK chunking is disabled
@batch_sizeINT2000Number of records per batch (SOAP API only)
@queryallBIT0When 1, includes deleted/archived records
@exists_actionVARCHAR(20)SLAM_Settings.default_exists_actionControls the behavior when the destination table name, specified by @table is already used. If NULL, uses the value from SLAM_Settings.default_exists_action (defaulted to 'drop' during initial setup).

Valid options:

  • 'drop' - Drop the existing object and create a new one (default)
  • 'rename' - Rename the existing object by appending a timestamp suffix (format: _YYYYMMDDTHHMMSS_MMM)
  • 'fail' - Throws a SQL exception if the destination object already exists

Usage Examples

Query using Bulk v1 API with PK Chunking:

EXEC dbo.SLAM_query
@query = 'Account',
@table = 'Account_query',
@api = 'bulk',
@pkchunksize = 100000

Query using SOAP API with custom batch size:

EXEC dbo.SLAM_query
@query = 'SELECT Id, Name, Email, Account.Name FROM Contact WHERE CreatedDate = TODAY',
@table = 'Contact_query',
@api = 'soap',
@batch_size = 1500

Query using Bulk v2 API for large datasets:

EXEC dbo.SLAM_query
@query = 'SELECT * FROM Opportunity WHERE CreatedDate > LAST_N_DAYS:365',
@table = 'Opportunity_query',
@api = 'bulkv2'