?
Solved

sql sproc procedure

Posted on 2015-02-22
4
Medium Priority
?
106 Views
Last Modified: 2015-02-22
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
Comment
Question by:fskilnik
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
  • 2
4 Comments
 
LVL 70

Accepted Solution

by:
Qlemo earned 2000 total points
ID: 40624555
Be consistent with your types! Both the isnull and the comparison should use strings.
If ISNULL(@OriginalImgQuestion, '') != ''

Open in new window

0
 

Author Comment

by:fskilnik
ID: 40624566
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
 
LVL 70

Expert Comment

by:Qlemo
ID: 40624586
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
 

Author Comment

by:fskilnik
ID: 40624597
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

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Confronted with some SQL you don't know can be a daunting task. It can be even more daunting if that SQL carries some of the old secret codes used in the Ye Olde query syntax, such as: (+)     as used in Oracle;     *=     =*    as used in Sybase …
In this article I will describe the Copy Database Wizard method as one possible migration process and I will add the extra tasks needed for an upgrade when and where is applied so it will cover all.
If you’ve ever visited a web page and noticed a cool font that you really liked the look of, but couldn’t figure out which font it was so that you could use it for your own work, then this video is for you! In this Micro Tutorial, you'll learn yo…
Add bar graphs to Access queries using Unicode block characters. Graphs appear on every record in the color you want. Give life to numbers. Hopes this gives you ideas on visualizing your data in new ways ~ Create a calculated field in a query: …

762 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question