473,387 Members | 1,834 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

can you please correct this syntax.........

hi this a part of the stored proc .....Actually the syntax is a problem .....i mean only the quotes ...i m getting an error in the stmt below. Can any one check this and let me knw

set @strCd = 'Cd =' + @Cd + @strCC + @strCd + 'and'+ Interface = 'P' and StatusId Not In (4,8)

thanks a lot in advance
Oct 4 '07 #1
4 1201
Shashi Sadasivan
1,435 Expert 1GB
No clue on what you are trying to do
but look at the = operator, it is not sorrounded in quotes.

that might be ther error.

This is trying to locate the error.....if you provide what error you recieved it would help a lot better

cheers
Oct 4 '07 #2
hi this a part of the stored proc .....Actually the syntax is a problem .....i mean only the quotes ...i m getting an error in the stmt below. Can any one check this and let me knw

set @strCd = 'Cd =' + @Cd + @strCC + @strCd + 'and'+ Interface = 'P' and StatusId Not In (4,8)

thanks a lot in advance
Hi actually

this is a stored proc which i have


@Cd Char(11),
@Id int,
@opt int,

AS
BEGIN
SET NOCOUNT ON

if @opt = 1 Begin
Select * from C_Eng with(nolock) Where Id = @d And SysInd = 'P' And statusId Not In (4,8)
End

if @opt = 2 Begin
Select * from C_Eng with(nolock) Where Cd = @Cd And SysInd = 'P' And StatusId Not In (4,8)
End

if @opt = 3 Begin
Select * from C_Eng with(nolock) Where Id = @Id And Cd = @Cd
And SysInd = 'P' And StatusId Not In (4,8)
End


SET NOCOUNT OFF
END



Now i want to modify this stored proc and make it dynamic, and also i want to include the startdate and end date so tht i can select the id which r created between the start and end date . the start date and end date have to be dynamic. if the end date is not given then we giv present date as the end date

so i have modified it like this ...

set @strMain = 'Select * from C_Eng with(nolock) Where '
@strId varchar(100)
Set @strId = ''
@strCd varchar(100)
Set @strCd = ''

if @Id is not null and rtrim(ltrim(@Id)) <> ''
set strId = 'Id = ' + @Id

if @Cd is not null and rtrim(ltrim(@Cd)) <> ''
set @strCd = 'Cd = ' + @Cd + @strId + @strCd + ' And SysInd = 'P' And StatusId Not In (4,8)


if @startDate is not null and rtrim(ltrim(@startDate)) <> '' and @enddate is not null and rtrim(ltrim(@enddate)) <> ''
set strOriginDate = ' and OriginDate between ' + @StartDate + ' and ' + @EndDate


set strMain = @strMain + @strCCR +
print strMain


and the foll are the errors
above i have declare the variables also ........Can u plZZZZZZZZZZZ help
Server: Msg 137, Level 15, State 1, Line 10
Must declare the variable '@strMain'.
Server: Msg 170, Level 15, State 1, Line 16
Line 16: Incorrect syntax near '='.
Server: Msg 170, Level 15, State 1, Line 19
Line 19: Incorrect syntax near 'P'.
Server: Msg 170, Level 15, State 1, Line 23
Line 23: Incorrect syntax near '='.
Server: Msg 128, Level 15, State 1, Line 27
The name 'strMain' is not permitted in this context. Only constants, expressions, or variables allowed here. Column names are not permitted.

IT WUD BE GR8 IF U HELP ME
THANKS A LOT IN ADVANCE
Oct 5 '07 #3
azimmer
200 Expert 100+
Hi actually

this is a stored proc which i have


@Cd Char(11),
@Id int,
@opt int,

AS
BEGIN
SET NOCOUNT ON

if @opt = 1 Begin
Select * from C_Eng with(nolock) Where Id = @d And SysInd = 'P' And statusId Not In (4,8)
End

if @opt = 2 Begin
Select * from C_Eng with(nolock) Where Cd = @Cd And SysInd = 'P' And StatusId Not In (4,8)
End

if @opt = 3 Begin
Select * from C_Eng with(nolock) Where Id = @Id And Cd = @Cd
And SysInd = 'P' And StatusId Not In (4,8)
End


SET NOCOUNT OFF
END



Now i want to modify this stored proc and make it dynamic, and also i want to include the startdate and end date so tht i can select the id which r created between the start and end date . the start date and end date have to be dynamic. if the end date is not given then we giv present date as the end date

so i have modified it like this ...

set @strMain = 'Select * from C_Eng with(nolock) Where '
@strId varchar(100)
Set @strId = ''
@strCd varchar(100)
Set @strCd = ''

if @Id is not null and rtrim(ltrim(@Id)) <> ''
set strId = 'Id = ' + @Id

if @Cd is not null and rtrim(ltrim(@Cd)) <> ''
set @strCd = 'Cd = ' + @Cd + @strId + @strCd + ' And SysInd = 'P' And StatusId Not In (4,8)


if @startDate is not null and rtrim(ltrim(@startDate)) <> '' and @enddate is not null and rtrim(ltrim(@enddate)) <> ''
set strOriginDate = ' and OriginDate between ' + @StartDate + ' and ' + @EndDate


set strMain = @strMain + @strCCR +
print strMain


and the foll are the errors
above i have declare the variables also ........Can u plZZZZZZZZZZZ help
Server: Msg 137, Level 15, State 1, Line 10
Must declare the variable '@strMain'.
Server: Msg 170, Level 15, State 1, Line 16
Line 16: Incorrect syntax near '='.
Server: Msg 170, Level 15, State 1, Line 19
Line 19: Incorrect syntax near 'P'.
Server: Msg 170, Level 15, State 1, Line 23
Line 23: Incorrect syntax near '='.
Server: Msg 128, Level 15, State 1, Line 27
The name 'strMain' is not permitted in this context. Only constants, expressions, or variables allowed here. Column names are not permitted.

IT WUD BE GR8 IF U HELP ME
THANKS A LOT IN ADVANCE
A couple syntax corrections in bold:
Expand|Select|Wrap|Line Numbers
  1. declare @strMain varchar(100)
  2. declare @Id varchar(100)
  3. declare @Cd varchar(100)
  4. declare @startdate varchar(100)
  5. set @strMain = 'Select * from C_Eng with(nolock) Where '
  6. declare @strId varchar(100)
  7. Set @strId = ''
  8. declare @strCd varchar(100)
  9. Set @strCd = ''
  10.  
  11. if @Id is not null and rtrim(ltrim(@Id)) <> ''
  12. set @strId = 'Id = ' + @Id
  13.  
  14. if @Cd is not null and rtrim(ltrim(@Cd)) <> ''
  15. set @strCd = 'Cd = ' + @Cd + @strId + @strCd + ' And SysInd = ''P'' And StatusId Not In (4,8)'
  16.  
  17.  
  18. if @startDate is not null and rtrim(ltrim(@startdate)) <> '' and @enddate is not null and rtrim(ltrim(@enddate)) <> ''
  19. set @strOriginDate = ' and OriginDate between ' + @startdate + ' and ' + @EndDate
  20.  
  21.  
  22. -- set strMain = @strMain + @strCCR +
  23. print @strMain
  24.  
Apart from this make sure your code makes sense. E.g. around the WHERE statement if you have no WHERE clause indeed...

Note: Some corrections do not show up in bold. See the code at "Reply".
Oct 5 '07 #4
A couple syntax corrections in bold:
Expand|Select|Wrap|Line Numbers
  1. declare @strMain varchar(100)
  2. declare @Id varchar(100)
  3. declare @Cd varchar(100)
  4. declare @startdate varchar(100)
  5. set @strMain = 'Select * from C_Eng with(nolock) Where '
  6. declare @strId varchar(100)
  7. Set @strId = ''
  8. declare @strCd varchar(100)
  9. Set @strCd = ''
  10.  
  11. if @Id is not null and rtrim(ltrim(@Id)) <> ''
  12. set @strId = 'Id = ' + @Id
  13.  
  14. if @Cd is not null and rtrim(ltrim(@Cd)) <> ''
  15. set @strCd = 'Cd = ' + @Cd + @strId + @strCd + ' And SysInd = ''P'' And StatusId Not In (4,8)'
  16.  
  17.  
  18. if @startDate is not null and rtrim(ltrim(@startdate)) <> '' and @enddate is not null and rtrim(ltrim(@enddate)) <> ''
  19. set @strOriginDate = ' and OriginDate between ' + @startdate + ' and ' + @EndDate
  20.  
  21.  
  22. -- set strMain = @strMain + @strCCR +
  23. print @strMain
  24.  
Apart from this make sure your code makes sense. E.g. around the WHERE statement if you have no WHERE clause indeed...

Note: Some corrections do not show up in bold. See the code at "Reply".
/thanks a lot . i relaised my mistakes and now it fine ....yea by mistake i dint put the where clause ..i was in hurry .got to submit it so.....thnaks a lot for ur patience and advice
Oct 5 '07 #5

Sign in to post your reply or Sign up for a free account.

Similar topics

72
by: Raymond Hettinger | last post by:
Peter Norvig's creative thinking triggered renewed interest in PEP 289. That led to a number of contributors helping to re-work the pep details into a form that has been well received on the...
4
by: Scotter | last post by:
Hi folx - Here is the code I'm trying (but it errors out with "Item cannot be found in the collection corresponding to the requested name or ordinal."): ...
1
by: Az Tech | last post by:
Hi people, (Sorry for the somewhat long post). I request some of the people on this group who have good experience using object-orientation in the field, to please give some good ideas for...
1
by: David Goodyear | last post by:
At the moment im experimenting with ideas in C++ and would really like to solve the following, please please help. Sorry i dont even know what the subject is this would come under? :( Sorry if...
3
by: msnews.microsoft.com | last post by:
Hello. I have this code in a project named ProductsHandler: First, a class called ProductsHandler.vb (this particular code is not important in this question, because the class is correct - it...
7
by: Jeff | last post by:
Hi - For my VB.NET app, I have a SQL2K database that I use to create a dataset with multiple data tables. I've created a dataview (dvReportsTo) of one of the tables, SCPMaster, and I've bound a...
1
by: David Van D | last post by:
Hi there, A few weeks until I begin my journey towards a degree in Computer Science at Canterbury University in New Zealand, Anyway the course tutors are going to be teaching us JAVA wth bluej...
1
by: Hollywood | last post by:
Hello dear membres of the comp.unix.programmer. Please , I've got the following question to submit and I need your help. Here below you'll find a lexical and a syntaxic analysers. The lexical...
11
by: Pranav | last post by:
The Code is compiling without Error/Bug/Exception.., What are the possibilities for this behaviour? //*************************************************************** #include<stdio.h> typedef...
5
by: Willzur21267 | last post by:
Private Sub Command82_Click() Dim strWhere As String List58.Selected(i) = False strWhere*=*"1=1" If Not*IsNull(Me.List58)*Then strWhere*=*strWhere*&*"*AND*(SiteName)*="&*Me.List58.Selected...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.