Thanks for the quick reply Jeremy.

What I'm going to try is to write out a custom row count and manually 
insert the Execute as User statement for each functionality - row count and 
iteration.

@sql = "SELECT * FROM [secure].[Employee Snapshot Fact] [Employee Snapshot 
Fact]"
def row_count
  "EXECUTE AS USER='ADND\\user'; SELECT COUNT(*) AS total_rows FROM 
(#{@sql}) x"
end

def query
  "EXECUTE AS USER='ADND\\user'; #{@sql}"
end

a = Sequel.connect(
"tinytds://#{ENV['SQL_SERVER_development_USERNAME']}:#{ENV['SQL_SERVER_development_PASSWORD']}@#{ENV['SQL_SERVER_development_HOST']}:#{ENV['SQL_SERVER_development_PORT']}/#{ENV['SQL_SERVER_development_DB']}"
)

a[row_count].first
=> {:total_rows=>4167860}

a[query].first
=> {:"employee key"=>126, :"job key"=>0, :"active faculty key"=>21, 
:"faculty appointment key"=>6, :"date key"=>20020630}

I have to watch out for ORDER BY. I think I'm just going to Regex out any 
order clauses at time of row_count. I found a good example here 
<https://regex101.com/r/jS5fN1/1#javascript>

-- 
You received this message because you are subscribed to the Google Groups 
"sequel-talk" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To post to this group, send email to [email protected].
Visit this group at https://groups.google.com/group/sequel-talk.
For more options, visit https://groups.google.com/d/optout.

Reply via email to