Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 Development Tools
 ASP.NET
 'string' within a SQL statement

Author  Topic 

fonzie
Starting Member

31 Posts

Posted - 2005-11-21 : 10:34:46
Hi, in using VB I am building a select statment but wonder how to do it right. In VB a ' means commented line and my statment is encompassed by double quotes. Any clues?

SqlDataSource1.SelectCommand = "SELECT [STATUS] FROM " & DropDownList2.SelectedItem.Text & " where [CUST] LIKE '%' + @CUST_NAME + '%' And [status] =" OPEN " '

nr
SQLTeam MVY

12543 Posts

Posted - 2005-11-21 : 10:39:44
SqlDataSource1.SelectCommand = "SELECT [STATUS] FROM " & DropDownList2.SelectedItem.Text & " where [CUST] LIKE '%' + @CUST_NAME + '%' And [status] = 'OPEN'"

All you will get is OPEN in the resultset though.

==========================================
Cursors are useful if you don't know sql.
DTS can be used in a similar way.
Beer is not cold and it isn't fizzy.
Go to Top of Page

fonzie
Starting Member

31 Posts

Posted - 2005-11-21 : 10:44:58
Right, but I want to get this working first with correctly placed quotes, but for now it's screwed up.
Go to Top of Page

fonzie
Starting Member

31 Posts

Posted - 2005-11-21 : 13:33:07
I finally got it, I guess no one wanted to touch this one?

SqlDataSource1.SelectCommand = "SELECT [STATUS] FROM " & DropDownList2.SelectedItem.Text & " where [CUST] LIKE '%' + @CUST_NAME + '%' And status = " + "'" & dropDownList1.SelectedItem.Text + "'"

I replaced with leteral STATUS with a varable. The quotes are tricky!

Go to Top of Page

druer
Constraint Violating Yak Guru

314 Posts

Posted - 2005-11-21 : 13:39:41
Typically I've just use a Character variable that was assigned to the single quote character. I think it is 34 or 39, you can find it.

SingleQuote = chr$(34) ' or whatever it should really be
MyString = "Blah blah blah " + SingleQuote + "whatever other text " + SingleQuote
Go to Top of Page
   

- Advertisement -