Showing posts with label incorrect. Show all posts
Showing posts with label incorrect. Show all posts

Sunday, March 25, 2012

Aaargh! Storedproc vs SQL in Gridview update

When I attempt to update using a stored procedure I get the error 'Incorrect syntax near sp_upd_Track_1'. The stored procedure looks like the following when modified in SQLServer:

ALTERPROCEDURE [dbo].[sp_upd_CDTrack_1]

(@.CDTrackNamenvarchar(50),

@.CDArtistKeysmallint,

@.CDTitleKeysmallint,

@.CDTrackKeysmallint)

AS

BEGIN

SETNOCOUNTON;

UPDATE [Demo1].[dbo].[CDTrack]

SET [CDTrack].[CDTrackName]= @.CDTrackName

WHERE [CDTrack].[CDArtistKey]= @.CDArtistKey

AND [CDTrack].[CDTitleKey]= @.CDTitleKey

AND [CDTrack].[CDTrackKey]= @.CDTrackKey

END

But when I use the following SQL coded in the gridview updatecommand it works:

"UPDATE [Demo1].[dbo].[CDTrack]

SET [CDTrack].[CDTrackName] = @.CDTrackName

WHERE [CDTrack].[CDArtistKey] = @.CDArtistKey

AND [CDTrack].[CDTitleKey] = @.CDTitleKey

AND [CDTrack].[CDTrackKey] = @.CDTrackKey"

Whats the difference? The storedproc executes ok in sql server and I guess that as the SQL version works all of my databinds are correct. Any ideas, thanks, James.

Not sure if it's the source of your problem, but shouldn't sp_upd_Track_1 and p_upd_CDTrack_1 be the same or was that a typo?

|||Yeah, typo, the correct name is specified in the storedproc and referenced correctly in the asp.

Monday, March 19, 2012

A story of incorrect syntax

Dear Group

Just can't see what I'm doing wrong. Any Ideas?

SELECT Address1, Address2, Suburb FROM i2b_address
IsNull (NullIf (Address1 + '', ''), '') +
IsNull (NullIf('','' + Address2,''),'') +
IsNull (NullIf('', '' + Suburb, ''), '') AS PropertyAddress

Server: Msg 156, Level 15, State 1, Line 2
Incorrect syntax near the keyword 'NullIf'.

Thanks for your help & efforts!

MartinSELECT Address1, Address2, Suburb,
IsNull (NullIf (Address1 + '', ''), '') +
IsNull (NullIf('','' + Address2,''),'') +
IsNull (NullIf('', '' + Suburb, ''), '') AS PropertyAddress
-- -> from clause goes here
FROM I2B_ADDRESS|||Hi! Well, something we don't notice the obvious! Thanks very much! I
think I need a break!
But still getting an error... Argh!!! What's wrong?

SELECT Address1, Address2, Suburb,
IsNull (NullIf (Address1 + '', ''), '') +
IsNull (NullIf('','' + Address2,''),'') +
IsNull (NullIf('', '' + Suburb, ''), '') AS PropertyAddress
FROM i2b_address

Server: Msg 170, Level 15, State 1, Line 3
Line 3: Incorrect syntax near ','.

Thanks for your help & efforts!

M|||Solved It!

IsNull (NullIf (Address1 + '', ''), '') +
IsNull (NullIf (', ' + Address2, ''), '') +
IsNull (NullIf (', ' + Suburb, ''), '') AS PropertyAddress|||If you use the Northwind database, Customers table, you'll see that
this also works...
I don't have your data structures and therefore need to use something I
do have...

SELECT ContactName, ContactTitle, Fax,
IsNull(NullIf (ContactName + ' ', ''), ' ') +
IsNull(NullIf(ContactTitle + ' ', ''), ' ') +
IsNull(NullIf(Fax + ' ', ''), ' ') AS PropertyAddress
FROM Customers