Re: Using a parameter for the filename in an SQL query

Tech-Archive recommends: Fix windows errors by optimizing your registry



The problem isn't with .NET, it's with SQL Server not letting you do
that. You'll need two different command strings, one for each table.

--Mary

On Mon, 9 May 2005 08:52:09 -0700, BBM <bbm@xxxxxxxxxxxxxx> wrote:

>Hi,
>
>I have a situation where I want to write the exact same record to two
>different files. One file is the "live" file and the second (defined
>identically to the first) is a "history log" of all previous states of the
>record.
>
>So I'd love to just run the same SQL command twice, with different
>filenames.
>
>I could just define two different strings for the text command and swap them
>out in the SQLCommand object, but I'd rather use a parameter in the SQL text
>to indicate the file name and not have to worry about synchronizing two
>versions of the same command for the life of the app.
>
>So I changed my insert command string to...
>
>INSERT INTO @Filename VALUES(@id, @Data1, @Data2, @Datax , etc. etc. )
>
>code is...
>Dim cmd as SQLCommand = New SQLCommand(InsertString, connection)
>'Add a bunch of parms for the data...
>'Set the value of all the data parms...
>cmd.Parameters.Add("@Filename", "MyfileName")
>cmd.ExecuteNonQuery()
>
>I get an SQL error on the Execute statement that says...
>"Must Declare the variable @Filename"
>
>I chose the two parameter version of Parameter.Add because it looked like
>the simplest approach. I just need to replace "@Filename" with "MyFileName".
>
>
>But I'm obviously not doing this right. First I looked to see what it takes
>to "Declare" a variable. I looked in my SQL Server book and it says that the
>Declare statement is a MS SQL extension, so I gave up this approach as I'd
>prefer not to start embedding MS specific SQL into my app.
>
>Is there a way to do this in ado.Net, or am I just going to have to
>manipuate the command text string to do the replacement?
>
>Thanks for your help.
>
>BBM

.



Relevant Pages

  • Re: COBOL stored procedure for DB2
    ... Regarding how you precompile the app, you must specify target mfcob to db2 prep, rather than target ibmcob. ... Have you also confirmed that, prior to executing the CALL statement, the host variables specified within the client app have the appropriate values? ... MODIFIES SQL DATA ... confirm the cob command used for creating the SP module. ...
    (comp.lang.cobol)
  • Re: Report to display data from sql serv.
    ... IIF (case statements in SQL Server) scenarios etc. ... then you need to create a Stored Procedure in SQL Server and use that as ... at run time supplying the parameters in code by using the Exec command. ...
    (microsoft.public.access.reports)
  • Re: Using a parameter for the filename in an SQL query
    ... > The problem isn't with .NET, it's with SQL Server not letting you do ... You'll need two different command strings, ... >>I get an SQL error on the Execute statement that says... ...
    (microsoft.public.dotnet.framework.adonet)
  • Re: COBOL stored procedure for DB2
    ... Have you also confirmed that, prior to executing the CALL statement, the ... The DB2 CREATE PROCEDURE statement. ... MODIFIES SQL DATA ... confirm the cob command used for creating the SP module. ...
    (comp.lang.cobol)
  • Re: Cannot open SQL 2000 default database
    ... 1> EXEC sp_default 'mylogin', ... I have to type EXIT or type ctrl-C to get out of the SQL editor. ... error as I did before the error, as though I didn't type the command prompt ... I assume here that you run OSQL on the SQL Server machine itself, ...
    (microsoft.public.sqlserver.connect)