Sorry about that, my union query is for an SQL server over our corporate network. The query creates two selection tables on the network SQL server. In the query there is two variables startdate and enddate, they are declared and selected in the query like this:
Originally Posted by r937
@startdate and @enddate is then later used to define the range of which records to be shown. But my problem is this. The dates on the records is not one of the columns presented in the result, but used temporarily on to the network SQL server when the query is runned. So I can't do a Select query based on the Union query to filter the records. Of course it could work if I included all the records ever created in the union query temporary databases, but then that file would be to big. That's why I want to be able to input the value myself. It works fine on a select query based on a linked table, but NOT on a union query asked directly to the SQL server. I thought I could write as suggested previously (as can be done in a select query)
SET NOCOUNT ON
DECLARE @startdate varchar(20)
DECLARE @enddate varchar(20)
-- variabel data
SELECT @startdate = '20040101 00:00:00'
SELECT @enddate = '20040331 00:00:00'
But that gave me the error message you can read above.
Select @startdate = [Please enter startdate: ]