[Last Call] Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 108
  • Last Modified:

sql sproc procedure

Hi there!

The procedure created/altered below works as expected:

----------------------------------
ALTER PROCEDURE [dbo].[net_upd_FullQuestDB_sproc]
(
      @questDBID int,
      @QuestLevel int = null
AS
BEGIN
  If ISNULL(@QuestLevel, 0) != 0
  BEGIN
  UPDATE dbo.QuestionsDB
  SET
  QuestLevel = @QuestLevel
  WHERE QuestDBID = @questDBID
  END
END

GO
----------------------------------

But the one below, which seems "logically" equivalent, does NOT work unless I try only numbers in the field...

ALTER PROCEDURE [dbo].[net_upd_FullQuestDB_sproc]
(
      @questDBID int,
      @OriginalImgQuestion nvarchar(150) = null
AS
BEGIN
  If ISNULL(@OriginalImgQuestion, 0) != 0
  BEGIN
  UPDATE dbo.QuestionsDB
  SET
  OriginalImgQuestion = @OriginalImgQuestion
  WHERE QuestDBID = @questDBID
  END
END

GO


It seems as if the procedure cannot take into account that I defined int in one case and nvarchar(150) in the other case... but it should consider that and make the second sproc work.... am I wrong?  (Of course I am, otherwise this would not be an EE post, right?!)

Please help!  :)

P.S.: when I run this procedure like:

SQLsproc =  "net_upd_FullQuestDB_sproc @questDBID = " & questDBID & ", @OriginalImgQuestion = N'" & OriginalImgQuestion & "'"

and I use OriginalImgQuestion  as say "1234" it works, but when I use the same field value as "abc", it does not work...
0
fskilnik
Asked:
fskilnik
  • 2
  • 2
1 Solution
 
QlemoC++ DeveloperCommented:
Be consistent with your types! Both the isnull and the comparison should use strings.
If ISNULL(@OriginalImgQuestion, '') != ''

Open in new window

0
 
fskilnikAuthor Commented:
Perfect, Qlemo!

It worked as expected, of course!  :)

Just one related-question, please: and when the type is "datetime", how should be the comparison (as strings)?

Thanks a lot!
fskilnik.
0
 
QlemoC++ DeveloperCommented:
To do it right is more difficult, as you do have no native date constant representation. But luckily any date can be converted to string. You can use exactly the same syntax as for strings - if you want to check for empty values, that is.
0
 
fskilnikAuthor Commented:
Great, Qlemo. Thanks for the info and for the answer to this post, of course!   :)

I have put another EE post VERY related to this a couple of minutes ago... if you have time, I would be very glad if you could help me there!!

There means Here: http://www.experts-exchange.com/Database/MS-SQL-Server/Q_28622155.html

Thanks a lot, really.

Regards,
fskilnik.
0

Featured Post

Keep up with what's happening at Experts Exchange!

Sign up to receive Decoded, a new monthly digest with product updates, feature release info, continuing education opportunities, and more.

  • 2
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now