Solved

sql sproc procedure

Posted on 2015-02-22
4
95 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
  • 2
  • 2
4 Comments
 
LVL 68

Accepted Solution

by:
Qlemo earned 500 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 68

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

Complete VMware vSphere® ESX(i) & Hyper-V Backup

Capture your entire system, including the host, with patented disk imaging integrated with VMware VADP / Microsoft VSS and RCT. RTOs is as low as 15 seconds with Acronis Active Restore™. You can enjoy unlimited P2V/V2V migrations from any source (even from a different hypervisor)

Join & Write a Comment

Suggested Solutions

If you find yourself in this situation “I have used SELECT DISTINCT but I’m getting duplicates” then I'm sorry to say you are using the wrong SQL technique as it only does one thing which is: produces whole rows that are unique. If the results you a…
In this article we will get to know that how can we recover deleted data if it happens accidently. We really can recover deleted rows if we know the time when data is deleted by using the transaction log.
Illustrator's Shape Builder tool will let you combine shapes visually and interactively. This video shows the Mac version, but the tool works the same way in Windows. To follow along with this video, you can draw your own shapes or download the file…
When you create an app prototype with Adobe XD, you can insert system screens -- sharing or Control Center, for example -- with just a few clicks. This video shows you how. You can take the full course on Experts Exchange at http://bit.ly/XDcourse.

758 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

Need Help in Real-Time?

Connect with top rated Experts

21 Experts available now in Live!

Get 1:1 Help Now