Solved

sql sproc procedure

Posted on 2015-02-22
4
103 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 69

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 69

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

PRTG Network Monitor: Intuitive Network Monitoring

Network Monitoring is essential to ensure that computer systems and network devices are running. Use PRTG to monitor LANs, servers, websites, applications and devices, bandwidth, virtual environments, remote systems, IoT, and many more. PRTG is easy to set up & use.

Question has a verified solution.

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

Introduction: When running hybrid database environments, you often need to query some data from a remote db of any type, while being connected to your MS SQL Server database. Problems start when you try to combine that with some "user input" pass…
If you have heard of RFC822 date formats, they can be quite a challenge in SQL Server. RFC822 is an Internet standard format for email message headers, including all dates within those headers. The RFC822 protocols are available in detail at:   ht…
Email security requires an ever evolving service that stays up to date with counter-evolving threats. The Email Laundry perform Research and Development to ensure their email security service evolves faster than cyber criminals. We apply our Threat…

825 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