Mathematica Stack Exchange is a question and answer site for users of Mathematica. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I'm using DatabaseLink to query MS SQL Server with SQLExecute which works totaly fine, for ex.:

SQLExecute[conn, "declare @dt date;
select * from ttable where date=@dt"]

However the problem starts when i try to use table variable and try to return it, for ex.:

SQLExecute[conn, "declare @dt date;
declare @tab table(
var1 int
date date)
insert into @tab
select * from ttable where date=@dt;
select * from @tab"]

It returns the number of rows and not the table. Is there a way to solve that? It seems that Mathematica returns results for the 'insert' statement, not the final results.

share|improve this question
up vote 8 down vote accepted

By default, SQL Server will return two result sets when it executes the exhibited SQL batch. The first result set contains the number of rows inserted by the INSERT statement. The second contains the rows from the SELECT statement. DatabaseLink will only report the first result set from a batch. However, you can tell SQL Server to avoid generating the first result set by adding the command SET NOCOUNT ON prior to the INSERT statement.

share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.