Showing posts with label statement. Show all posts
Showing posts with label statement. Show all posts

Thursday, March 29, 2012

Error: Forward dependencies are not valid

I want to set a Report Parameter on a field. The Report Parameter is called 'filter'. In the statement I put the Report Parameter in the WHERE-part:
WHERE ([DatabaseName$TableName].[FieldName] = @.filter). After this I set the 'Available values' on the Report Parameter in the lay-out to Non-queried.
When the report is running, no problems.

But.....

Now I want to set 'Available values' on 'From Query' and refer to the data set, so the user can choose on which value he want to filter. But now, after running the preview the following error displays:
Error1[rsInvalidReportParameterDependency]The report parameter ‘filter’ has a DefaultValue or a ValidValue that depends on the report parameter “filter”. Forward dependencies are not valid.

Why can't I set the Report Parameter to 'From Query'? Anyone any suggestions?

(you can see the rest of my statement here: http://forums.microsoft.com/MSDN/ShowPost.aspx?PostID=1098540&SiteID=1)

Thx a lot of helping me out with this topic.....

Hi,

If I get it right, you have a dataset that you want to filter by a parameter 'FILTER' and the possible values for the filter also from the same dataset?

This is not possible since if you are requesting the possible values for the filter he will execute the query in the dataset. Since this dataset requires a parameter filter to be able to execute, you are having a loop.

What you should do is to make the 'From Query' property refer to a different dataset.

NOTE: Reporting Services first performs the queries in the same order as the Parameters have been set. Therefor, if the dataset of a given parameter needs the value of a second parameter, you need to make sure that this second parameter is standing above the first parameter in the parameter list.

Greetz,

Geert

Geert Verhoeven
Consultant @. Ausy Belgium

My Personal Blog

|||

Geert,

thx for your support. I've found a solution for my specific situation. I will drop it here for others with the same problem:

1. Report Parameter, Available non-queried.
- At Label I've filled in the options that I want to see in the pulldown menu.
- At Value I've filled in the values form my table (in this case only 4 or 5)
2. At the table properties, tab filtering I've made a filterlist called
- expression: =Fields!FieldName.Value
- operator: '='
- value : =Parameters!ParameterName.Value

This solution is only usefull if you don't have too much options to choose (because you have to fill in all the options manually..... )

Error: Expected End of Statement

I just don't see it (SSRS 2005 Expression Syntax Error):

=((Fields!PostedAmount_InHouse.Value + Fields!NewPDs_Check.Value + Fields!NewCCs_Check.Value) / Fields!CurrentPostingDay.Value) * (Fields!TotalPostingDays.Value - Fields!CurrentPostingDay.Value) + (Fields!PostedAmount_InHouse.Value + Fields!OldPDs_Check.Value + Fields!NewPDs_Check.Value + Fields!OldCCs_Check.Value + Fields!NewCCs_Check.Value) * Fields!FeeSchedule.Value)) / 100

Error: Expected End of Statement

4( + 6) = Error: Expected Endof Statement

Error: Contains more than the maximum number of prefixes. The max

I am running an update statement in query analyzer to update a database with
data from another database on another server.
I am running into the error : Error: Contains more than the maximum number
of prefixes. Maximum is 3
How do I overcome this error. I am the admin on both servers.http://www.sqlteam.com/forums/topic.asp?TOPIC_ID=44062
DishanF
*** Sent via Developersdex http://www.examnotes.net ***
Don't just participate in USENET...get rewarded for it!|||I was trying to do something similar by doing an update and "pushing" the da
ta across to a linked server with the following:
update ServerName.AAD.dbo.t_employee
set ServerName.AAD.dbo.t_employee.work_shift = wa.work_shift
from t_employee wa
where ServerName.AAD.dbo.t_employee.id = wa.id
and wa.id = '105'
I was also getting the following:
Server: Msg 117, Level 15, State 2, Line 4
The number name 'ServerName.AAD.dbo.t_employee' contains more than the maxim
um number of prefixes. The maximum is 3.
It's a simple, but not obvious, answer. Put the table you are updating in th
e FROM clause with an alias and update the alias, as follows:
update la
set la.work_shift = wa.work_shift
from ServerName.AAD.dbo.t_employee la, t_employee wa
where la.id = wa.id
and wa.id = '105'
You have to love simple answers. Finding them is the challenging part. :)sql

Error: Contains more than the maximum number of prefixes. Maximum

I am running an update statement in query analyzer to update a database with
data from another database on another server.
I am running into the error : Error: Contains more than the maximum number
of prefixes. Maximum is 3
How do I overcome this error. I am the admin on both servers.
> I am running an update statement in query analyzer to update a database
with
> data from another database on another server.
> I am running into the error : Error: Contains more than the maximum number
> of prefixes. Maximum is 3
> How do I overcome this error. I am the admin on both servers.
Object names in SQL Server have 4 parts: server.database.owner.objectname
Therefore, you ca have only 3 prefixes. Check the names in your Update
query.
Dejan Sarka, SQL Server MVP
Associate Mentor
www.SolidQualityLearning.com

Tuesday, March 27, 2012

ERROR:- An INSERT EXEC statement cannot be nested.

HI,

WELL WE HAVE BEEN TRYING TO AUTOMATE A PROCEDURE OUT HERE,AND WE ARE TRYING TO CONVERT MOST OF THE THINGS INTO PROCEDURES.

BUT WE ARE GETTING A FEW HICCUPS. PLS HELP

THIS IS HOW IT GOES :-

CREATE PROCEDURE MY_PROC1
AS
BEGIN
ST1 .......;
ST2........;
END

CREATE PROCEDURE MY_PROC2
AS
BEGIN

CREATE TABLE #TMP2
(COL1 DATATYPE
COL2 DATATYPE)

INSERT INTO #TMP2
EXEC MY_PROC1

ST1 .......;
ST2........;

END

THIS PROCEDURE TOO RUNS WELL ,AFTER TAKING THE DATA FROM THE FIRST PROC IT MANIPUATES THE DATA ACCORDING TO THE CRITERIA SPECIFIED

NO PROBLEM TILL NOW......

BUT,

CREATE PROCEDURE MY_PROC3
AS
BEGIN

CREATE TABLE #TMP3
(COL1 DATATYPE
COL2 DATATYPE)

INSERT INTO #TMP3
EXEC MY_PROC2

ST1 .......;
ST2........;

END

THEN IT GIVES AN ERROR AS :-

"An INSERT EXEC statement cannot be nested."

CAN'T WE , FROM A PROCEDURE CALL A PROCEDURE WHICH CALLS A PROCEDURE......

WHAT IS THE NESTING LEVEL OF A PROCEDURE ?

IS THERE ANY WAY AROUND IT OR CAN IT BE DONE BY CHANGING SOME SETTINGS ?

PLS HELP ME OUT IN THIS

THANKSYou can nest stored procedures pretty deep (I think it's 32 levels or so). What you cannot do is have an INSERT #TMP3 EXEC proc1 in one procedure and have the next procedure that calls it with an INSERT #TEMP EXEC proc2.

You have to architect around this limitation. There is no setting to change the above that I'm aware of.|||Hi,

Thanks Derrick, But Is There A Way You Know To Get Around This One.

I Could Use Permanent Tables To Get Around This But It Takes Too Much Space,which Is A Constraint In Our Case.

Have To Use Temp Table :-

Is There A Way Around It ,as I Am Using The Results Of The First Procedure To Drive The Second One And The Results Of The Second One To Drive The Third .

Pls , If You Know Of Anything Pls Let Me Know.

Thanks.|||Without manual intervention, one level of INSERT...EXECUTE is the limit.

To do what you want, you really need an N-tier server. You can sort of kludge it via multiple instances, but you run out of RAM pretty quickly. You can also kludge it by compounding your cursor (rolling up all of the logically nested SELECTs into a single monster query).

There are a number of choices available, but due to your tight restrictions on RAM and disk, very few of those choices make good sense.

-PatP|||Hi,

I Got The Point Of Set -level Processing Rather Than Row-level Processing As You Had Said Before.so I Might Do Away With The Cursor Thing Altogether.but Is There Any Way To Use Mulitple Insert..exec Statement.

Now,that I Am Not Using Cursors ,i Don't Think Ram And Disk Matters Much Now.

Is There Any Way Out Of It Now ? Pls Do Help

Thanks.|||No. That's what we're trying to tell you. What you can do is have multiple queries that INSERT into a regular "process" table, which is just a normal table that records processes. You can then have a wrapper query that runs these in order. As long as all of your inserts are occurring on the second level, as opposed to the first order of queries meaning the wrapper query, you can run these infinitely.

Our EMC SnapClone process uses this methodology.|||Hi,

Thanks Derrick For The Help,but Frankly Speaking Being Still A Newcomer In The Field Of Ms-sql Databases.some Of The Words You Have Said Have Escaped My Vivid Imagination. Could You Pls Explain Me.

First,

What Do You Mean By A Wrapper Query ?

Second,

How To Implement It In Out Here ?

Could You Pls Explain This ?

Thanks.|||First,

What Do You Mean By A Wrapper Query ?
--This is just a query that call several subqueries and has overall control of a process.

Second,

How To Implement It In Out Here ?

Have each query right the results to a regular table. The query controls the overall process by reading these tables and deciding which query it needs to run next. As long as you stay one level under the wrapper query, you can run as many of these INSERT EXEC statements as you need to. If you post your query, I should be able to help you out more.|||DROP PROCEDURE PROC1
CREATE PROCEDURE PROC1
AS
BEGIN
SELECT A.INTCUSTOMERID,A.CHREMAIL,B.INTPREFERENCEID,C.CHR PREFERENCEDESC
FROM CUSTOMER A
INNER JOIN CUSTOMERPREFERENCE B
ON A.INTCUSTOMERID = B.INTCUSTOMERID
INNER JOIN TMPREFERENCE C
ON B.INTPREFERENCEID = C.INTPREFERENCEID
WHERE B.INTPREFERENCEID IN (6,7,2,3,12,10)
ORDER BY B.INTCUSTOMERID
END

DROP PROCEDURE PROC2
CREATE PROCEDURE PROC2
AS
BEGIN

CREATE TABLE #SAATHI(INTCUSTOMERID INT,CHREMAIL NVARCHAR(60),INTPREFERENCEID INT,CHRPREFERENCEDESC NVARCHAR(50))

INSERT INTO #SAATHI
EXEC PROC1

SELECT A.INTCUSTOMERID,MAX(case when A.intpreferenceid = 6 then '1'
else '0' end) +
MAX(case when A.intpreferenceid = 7 then '1'
else '0' end) +
MAX(case when A.intpreferenceid = 2 then '1'
else '0' end) +
MAX(case when A.intpreferenceid = 3 then '1'
else '0' end) +
MAX(case when A.intpreferenceid = 12 then '1'
else '0' end) +
MAX(case when A.intpreferenceid = 10 then '1'
else '0' end) AS PREFER
FROM #SAATHI A
GROUP BY A.INTCUSTOMERID
ORDER BY A.INTCUSTOMERID
END

DROP PROCEDURE PROC3
CREATE PROCEDURE PROC3
AS
BEGIN
CREATE TABLE #SAATH2(INTCUSTOMERID INT,TOTAL_COUNTS INT)

INSERT INTO #SAATH2
EXEC PROC2

DECLARE @.EKEK INT
DECLARE @.KAUNSARE VARCHAR(100)
SET @.EKEK = 1
SET @.KAUNSARE = 'International Pop'
WHILE @.EKEK <= 3
BEGIN
SELECT @.KAUNSARE AS NAAMRE,COUNT(*) AS TOTAL_COUNTS
FROM SAATH
WHERE SUBSTRING(PREFER,@.EKEK,1) = 1
GROUP BY SUBSTRING(PREFER,@.EKEK,1)
SET @.EKEK = @.EKEK + 1
IF @.EKEK=2
BEGIN
SET @.KAUNSARE = 'International Rock'
END
IF @.EKEK=3
BEGIN
SET @.KAUNSARE = 'Hindi Pop'
END
END
END

OUT HERE, THE PROBLEM ARISES IN PROC3 ,

THE THING IS THE RESULT OF 1 PROC IS I/P TO SECOND ONE AND THE RESULT OF 2 PROC IS I/P TO THIRD ONE.

COULD YOU DO SOMETHING ABOUT IT ?

HOW COULD WE IMPLEMENT WRAPPER QUERY OUT HERE, AS MAINTAINING ALL 3 PROCS ARE NECESSARY AS THEY ARE ALSO I/P'S TO OTHER PROCS.

AND SO ON ....

THANKS|||Here is an example of how to do it. ME is a linked server back to the same.

create proc a
as
select a = 'a'
go

create proc b
as
create table #b (b varchar(32) not null)
insert #b exec ME.master.dbo.a
select * from #b
go

create proc c
as
create table #c (c varchar(32) not null)
insert #c exec ME.master.dbo.b
select * from #c
go

create proc d
as
create table #d (d varchar(32) not null)
insert #d exec ME.master.dbo.c
select * from #d
go

exec d
go|||HI,

WHAT DO YOU MEAN BY :-
"ME is a linked server back to the same."

AND ANY WAY IF I AM USING : -

create proc a
as
select a = 'a'
go

create proc b
as
create table #b (b varchar(32) not null)
insert #b exec a
select * from #b
go

create proc c
as
create table #c (c varchar(32) not null)
insert #c exec b
select * from #c
go

create proc d
as
create table #d (d varchar(32) not null)
insert #d exec C
select * from #d
go

exec d
go

I AM GETTING AN ERROR WHICH IWAS GETTING BEFORE :-

"An INSERT EXEC statement cannot be nested."

HASN'T MADE MUCH DIFFERENCE ?

WHAT IS ME .. IS IT PRESENT IN ALL OF THE SQL SERVER 2000 ?

OR IS IT SOMETHING VIRTUAL THAT YOU HAVE CREATED ?

THANKS.|||"ME" is a linked server. In Enterprise Manager, open the Security folder, right click on Linked Servers, choose New Linked Server from the menu. I named the server "ME." Select "Microsoft OLE DB Provider for SQL Server" as the provider. Enter the actual name of your server in the Data Source field. On the security tab, select "Be made using the login's current security context." On the server options tab, check all of the check boxes.|||HI,

I AM GETTING AN ERROR THAT SAYS :-

"Could not find stored procedure 'master.dbo.a'.
Could not relay results of procedure 'a' from remote server 'ME'."

COULD YOU PLS EXPLAIN ME THE FUNDA OF LINKED SERVERS .?

I AM JUST BLINDLY F9OLLOWING YOU. AND GETTING NOWHERE .

PLS EXPLAIN IT TO ME.

THANKS,

CHETAN B.|||HI,

I AM GETTING AN ERROR THAT SAYS :-

"Could not find stored procedure 'master.dbo.a'.
Could not relay results of procedure 'a' from remote server 'ME'."

COULD YOU PLS EXPLAIN ME THE FUNDA OF LINKED SERVERS .?

I AM JUST BLINDLY FOLLOWING YOU. AND GETTING NOWHERE .

PLS EXPLAIN IT TO ME.

THANKS,

CHETAN B.

Wednesday, March 7, 2012

error with SQL statement

hi, i try the below sql code, however when i try to execute the command, it always give me the error 'Cannot use an aggregate or a subquery in an expression used for the group by list of a GROUP BY clause.'

If i remove the "(SELECT [description] = CASE WHEN ([description]) <> '' THEN [description] ELSE [tbl_batch_completed].[status] END)" under the group by clause, it will work

do I need to change something in the sql statement?

Thanks in advance

SELECT TAG_FACE_CON.REQUEST_ID,
(SELECT [description] = CASE WHEN ([description]) <> '' THEN [description] ELSE [tbl_batch_completed].[status] END)AS status

FROM (TAG_FACE_CON RIGHT JOIN tbl_batch_completed ON TAG_FACE_CON.GROUP_ID = tbl_batch_completed.ID)
GROUP BY TAG_FACE_CON.REQUEST_ID,(SELECT [description] = CASE WHEN ([description]) <> '' THEN [description] ELSE [tbl_batch_completed].[status] END)

You are going to have to remove the select staement from the group by. Also in that SQl Staement there is no from clause... It does not know where to get the batch completed information.

I would look into create a temp table to create the first section as raw data, then when you need to do the group by run it as a query from the temp table.|||I think restructuring your query like this will solve your problem:


SELECT
TAG_FACE_CON.REQUEST_ID,
CASE
WHEN [description] <> '' THEN [description]
ELSE [tbl_batch_completed].[status]
END AS status
FROM
TAG_FACE_CON
RIGHT JOIN
tbl_batch_completed ON TAG_FACE_CON.GROUP_ID = tbl_batch_completed.ID
GROUP BY
TAG_FACE_CON.REQUEST_ID,
CASE
WHEN [description] <> '' THEN [description]
ELSE [tbl_batch_completed].[status]
END

Terri

Error with Select Statement using the SQLDataAdapter Wizard

Error with Select Statement using the SQLDataAdapter Wizard
------------------------

I am needing to setup the data adapter for my SQL database for use with a web page that submits employment applications. When using the wizard I get this error: Incorrect syntax near the keyword 'FROM'. Beings that the code is generated by VB I am confused what would be incorrect. If anyone can see the problem please let me know. THANKS!

Here is the code that is giving me the error:

SELECT
FROM
[Personal Info] INNER
JOIN
Education ON
[Personal Info].[Applicants SSN] = Education.[Applicants SSN] INNER JOIN Legal ON [Personal Info].[Applicants SSN] = Legal.[Applicants SSN] INNER JOIN [Military Service] ON [Personal Info].[Applicants SSN] = [Military Service].[Applicants SSN] INNER JOIN [Employment History] ON [Personal Info].[Applicants SSN] = [Employment History].[Applicants SSN] INNER JOIN [References] ON [Personal Info].[Applicants SSN] = [References].[Applicants SSN] INNER JOIN [Farm Preference] ON [Personal Info].[Applicants SSN] = [Farm Preference].[Applicants SSN]

Quote:

Originally Posted by sds50

Error with Select Statement using the SQLDataAdapter Wizard
------------------------

I am needing to setup the data adapter for my SQL database for use with a web page that submits employment applications. When using the wizard I get this error: Incorrect syntax near the keyword 'FROM'. Beings that the code is generated by VB I am confused what would be incorrect. If anyone can see the problem please let me know. THANKS!

Here is the code that is giving me the error:

SELECT
FROM
[Personal Info] INNER
JOIN
Education ON
[Personal Info].[Applicants SSN] = Education.[Applicants SSN] INNER JOIN Legal ON [Personal Info].[Applicants SSN] = Legal.[Applicants SSN] INNER JOIN [Military Service] ON [Personal Info].[Applicants SSN] = [Military Service].[Applicants SSN] INNER JOIN [Employment History] ON [Personal Info].[Applicants SSN] = [Employment History].[Applicants SSN] INNER JOIN [References] ON [Personal Info].[Applicants SSN] = [References].[Applicants SSN] INNER JOIN [Farm Preference] ON [Personal Info].[Applicants SSN] = [Farm Preference].[Applicants SSN]


You haven't selected anything. You should have:

SELECT field1,field2 ... etc
FROM ...

Sunday, February 26, 2012

Error with Jump to Javascript statement

I have the following statement being used in the Jump to command.
= "javascript:void(window.open('" &
http://domainname/ReferralForm.aspx?ReferralID= "& Fields!REF_ID.Value &
','_blank'))"
When I try to preview the report, I get the following error in the task list
The hyperlink expression for the textbox "REF_ID" contains a colon or a line
terminator. Colons and line terminators are not valid in expresssions.This should work:
="javascript:void(window.open('http://domainname/ReferralForm.aspx?ReferralID="
& Fields!REF_ID.Value & "','_blank'))"
--
This posting is provided "AS IS" with no warranties, and confers no rights.
"scuba79" <scuba79@.discussions.microsoft.com> wrote in message
news:D6B0AAD2-44FB-48F4-9DD2-F598FFD7D52E@.microsoft.com...
>I have the following statement being used in the Jump to command.
> = "javascript:void(window.open('" &
> http://domainname/ReferralForm.aspx?ReferralID= "& Fields!REF_ID.Value &
> ','_blank'))"
>
> When I try to preview the report, I get the following error in the task
> list
> The hyperlink expression for the textbox "REF_ID" contains a colon or a
> line
> terminator. Colons and line terminators are not valid in expresssions.

error with c# select statement

hi i have copied this from my other page where it works fine and i cant understand what is going wrong! maybe one of your guys can point out what i cant see! herei s my code

string strOrderID = Request.QueryString["orderID"].ToString();

int intOrderID =Convert.ToInt32(strOrderID);

int intCustID =Convert.ToInt32(Request.QueryString["qsnOrderCustID"].ToString());

lblCustomerID.Text = Request.QueryString["qsnOrderCustID"].ToString();lblOrderID.Text = Request.QueryString["orderID"].ToString();

SqlConnection myConn =newSqlConnection("Data Source=xxxx;Initial Catalog=xxxx;User ID=xxxx;Password=xxxx");

//This is the sql statement.

string sql ="SELECT [del_address], [del_post_code], [del_time] From tbl_del WHERE order_ID = " + intOrderID;

//This creates a sql command which executes the sql statement.

SqlCommand sqlCmd =newSqlCommand(sql, myConn);

myConn.Open();

SqlDataReader dr = sqlCmd.ExecuteReader();

//This reads the first result from the sqlReader

dr.Read();

try

{

lblDelTime.Text =Convert.ToString(dr["del_time"].ToString);

lblDelAddy.Text = dr["del_address"].ToString();

lblDelPCode.Text = dr["del_post_code"].ToString();if (lblDelAddy.Text !="")

{

lblDelDate.Visible =true;

lblDelTime.Visible =true;

Label1.Visible =true;

Label2.Visible =true;

}

}

catch (Exception except)

{

lblerror.Text =Convert.ToString(except);

}

Regards

Jez

What error are you getting?

|||

try

{

lblDelTime.Text =Convert.ToString(dr["del_time"].ToString);

lblDelAddy.Text = dr["del_address"].ToString();

lblDelPCode.Text = dr["del_post_code"].ToString();if (lblDelAddy.Text !="")

{

lblDelDate.Visible =true;

lblDelTime.Visible =true;

Label1.Visible =true;Label2.Visible =true;

}

}

catch (Exception except)

{

lblerror.Text =Convert.ToString(except);

}

I can only find the above problem in the code...if you can name the error it will be more helpful for us.

|||

i realised that i was being a complete idiot (thats what being up for to long does! makes you miss the obvious!) i took a look at the bigger picture, it said that the textbox wasnt being filled, so maybe a problem with the data reader, no, but because i have 2 data readers on one page and i just copied and pasted the code, i forgot to put dr2[" instead of dr["

Friday, February 24, 2012

Error while trying to execute an SP in my CASE STATEMENT

Hi all,
How do i execute a stored procedure in the THEN CLAUSE of my CASE STATEMENT? Av been getting errors since.

Here is my code:

Alter PROCEDURE sp_getTxn (
@.m1 int = Null,
@.txn int = Null,
@.p2 int = Null,
@.amt int = Null,
@.pAccountno varchar(50) = 'Null',
@.DAcct int = Null,
@.Balance Decimal(19,4) = NULL OUTPUT,
@.pBalance Decimal(19,4) = NULL OUTPUT,
@.RowsReturned smallint = NULL OUTPUT )
AS
SET NOCOUNT ON

select CASE
WHEN @.m1 = 200 THEN case
when @.txn = 00 then ('exec dbo.CustOrderHist (@.CrAcct int)')

when @.txn = 01 then ('exec dbo.Sp_withdrawal')

when @.txn = 31 then exec dbo.CheckBalance(@.pAccountno varchar(50), @.pBalance Decimal(19,4) OUTPUT)

when @.txn = 38 then ('exec dbo.Sp_StatementOfAcct')
END
END
WHEN @.m1 = 420 THEN case
when @.txnType = 00 then ('exec dbo.Sp_reversal')

when @.txnType = 01 then ('exec dbo.Sp_reversal2')

when @.txnType = 31 then ('exec dbo.Sp_reversal3')
END
END

SET @.Balance = @.pBalance
Print @.Balance

Or is there an alternative to the above CASE statement that is easier and faster?

ThanksUse IF instead of CASE:
IF @.m1 = 200
BEGIN
IF @.txn = 00
BEGIN
exec dbo.CustOrderHist (@.CrAcct int)
END
ELSE IF @.txn = 01
BEGIN
exec dbo.Sp_withdrawal
END
ELSE IF @.txn = 31
...
END
ELSE IF @.m1 = 420
BEGIN
...|||Thanks for the response, the if--else--if works.
...

Wednesday, February 15, 2012

Error while executing a a query string using EXEC statement

Hi,

I have written a stored proc to bulk insert the data from a data file.

I have a requirement that i need to insert the data into a table of which the name is not known. I mean to say that the table name will be passed as a parameter to the stored proc. And also i need to insert the date that will also be passed as the parameter to the stored proc

The follwing statement works fine if i give the table name directly in the query

Code Snippet

DECLARE @.LastUpdate varchar(20)

SET @.LastUpdate = 'Dec 11 2007 1:20AM'

INSERT INTO Category

SELECT MSISDN, @.LastUpdate FROM OPENROWSET( BULK '\\remotemachine\datafile.txt',

FORMATFILE = '\\remotemachine\FormatFile.fmt',

FIRSTROW = 2) AS a

To satisfy my requirement ( i.e passing the table name dynamically , and the date) , i have formed the query string ( exact one as above ) and passing it to EXEC statement. But its failing as explained below

Code Snippet

@.Category - Will be passed as a parameter to the stored proc

DECLARE @.vsBulkSQL VARCHAR(MAX)

DECLARE @.LastUpdate varchar(20)

SET @.LastUpdate = 'Dec 11 2007 1:20AM'

SELECT @.vsBulkSQL ='INSERT INTO '+ @.Category + ' SELECT MSISDN, ''' + @.LastUpdate +''' FROM OPENROWSET ' + '( BULK ' + '''' + '\\remotemachine\datafile.txt'+ ''''+ ' ,' +

+ ' FORMATFILE ' + '=' + ''''+ '\\remotemachine\FormatFile.fmt'+ ''''+ ',' +

' FIRSTROW ' + '=' + '2' + ')' + ' AS a'

Print @.vsBulkSQL - This prints the folliwing statement

INSERT INTO Category SELECT MSISDN, 'Dec 11 2007 1:20AM' FROM OPENROWSET ( BULK '\\remotemachine\DataFile.txt' , FORMATFILE ='\\remotemachine\FormatFile.fmt', FIRSTROW =2) AS a

Exec @.vsBulkSQL - This statement gives the following error

The name 'INSERT INTO Sports SELECT MSISDN, 'Dec 11 2007 1:20AM' FROM OPENROWSET ( BULK '\\remotemachine\Second.txt' , FORMATFILE ='\\remotemachine\FormatFile.fmt', FIRSTROW =2) AS a' is not a valid identifier.

Can any one please point out where am i doing wrong? Or do i need to do anything else to achive the same

~Mohan

Does it work if you alias the @.LastUpdate value?

|||

I suspect you need to execute the query with

EXEC (@.vsBulkSQL)

You have left out the parentheses, and when you do that, EXEC expects the variable to hold a procedure name, not a query string.

Steve Kass

Drew University

www.stevekass.com

|||

Steve,

Good catch. Its working now if i have the string etween ( and ).

Thanks a lot

~Mohan