.NET Tutorials, Forums, Interview Questions And Answers
Welcome :Guest
Sign In
Register
 
Win Surprise Gifts!!!
Congratulations!!!


Top 5 Contributors of the Month
MarieAdela
Imran Ghani
Post New Web Links

Comparing Binary values in sp_executesql

Posted By:      Posted Date: September 19, 2010    Points: 0   Category :Sql Server
 

Hello,

I am using a stored procedures to handle some maintainance stuff in my DB, I have a binary field called Container, that for all rows that have that specific container I need to remove the oldest n rows, I also have a time field so I can order by it, in addition my table is recursive and so if I delete one value I need to delete all it's children.

So in short what I did is create a CTE that selects all the lines that I want to delete, using SELECT TOP @n FROM mytable WHERE Container=@Container

Now I had to use sp_executesql due to using a variable to declare the TOP value, but now it won't let me compare the binary value stating that nvarchar and varbinary data types are incompatible through add operator (I tried to do Container='+@Container+')

How can I do this properly?

Thanks!




View Complete Post


More Related Resource Links

Comparing Enum values in a collection - BC42025: Access of shared member, constant member, enum mem

  

I am upgrading from asp1.1 to 2.0

I use collection classes to sort data (e.g in datagrids etc)

Public

Enum newsFields
      title
End Enum

Public Overloads Sub Sort(ByVal sortField As newsFields, ByVal isAscending As Boolean)
   
Select Case sortField
         
Case newsFields.title
                     
MyBase

Comparing Null Values(from variable) in SSIS

  
Hi All I need to create a script that checks to see if a variable value is NULL, if it is then it executes the next SQL Task and if not then the package has finished. I have this in a SQL 2000 DTS package script: Function Main() If isnull(DTSGlobalVariables("NextLoadDate")) Then Main = DTSStepScriptResult_DontExecuteTask Else Main = DTSStepScriptResult_ExecuteTask End if End Function As you can see, all I want to do is check to see if a variable is null then don't execute the next task. But i cannot get it to work in a SQL 2005 SSIS package, so far I have created a script and come up with the following: Public Sub Main() If Dts.Variables("NextLoadDate").Value.ToString <> "" Then Dts.TaskResult = Dts.Results.Success Else Dts.TaskResult = Dts.Results.Failure End If End Sub Any Ideas? Thanks BigGopher

Comparing columns with NULL values--Merge says unmatched when data is matched.

  
I found the article below describing this same issue with the Oracle merge statement.  It also described a work-around:    http://searchoracle.techtarget.com/tip/Merging-datasets-with-NULL-values I have been unable to find a solution to this issue for SQL Server 2008.  I am trying to do basic ETL from Staging table to a Type II dimension table in a Data Warehouse.  I am using the Merge statement with the Unique key minus the modification date as my merge key list.  I have a handful of columns (in both Staging and the DW) containing nulls in my merge key list.  I have tried the ISNULL function and the ANSI_NULL db option (OFF) with no success.  When I put zeros in the null columns, it works as expected.  I am about to try separate INSERT and UPDATE statements, but I fear that the NULL comparison issue will bite me there with the JOIN statement.  Has anyone else experienced this?  NULL values are valid in our Data Warehouse.  How can I make T-SQL handle them? Thank you for your help, Jesse

comparing date values

  
ScenarioI have records that have an initial value of 'blue' and stay 'blue' until after 2 days then they turn to 'green', Turn 'orange' after 15 days and then after 20 days turn 'red'.The results will be pulled into a gridview.What I'm having difficulty is; what's the best way of calculating the days, in sql server or in c#?Trying to get construct date examples is proving to be a bit of a pain: DateTime TodaysDate = DateTime.Now; DateTime SelectedDate = Calendar1.SelectedDate; TimeSpan result = SelectedDate - TodaysDate; int days = result.Days; lblCalculateDays.Text = days.ToString(); TextBox1.Text = TodaysDate.ToString("d"); TextBox2.Text = SelectedDate.ToString("d"); protected void Calendar1_SelectionChanged(object sender, EventArgs e) { putDateInBox(); } protected void putDateInBox() { lblCalDate.Text = Calendar1.SelectedDate.ToShortDateString(); }has anyone done something similar and found a good way of doing this?

display / insert values by comparing 2 columns of a table

  

hi

i have a table which has the following columns 

A_ID, A_Value,A_Date,B_ID,B_Value_B_Date

 

i have another table as follows

A_ID,B_ID,A_Value,B_Value, Date

 

this is to be done 

* if A_date and B date are equal, one record shoould be entered to the TABLE 02. the values should be A_ID,B_ID,A_Value_B_Value and A_Date (since the date is equal, no problem; even can insert B_Date instead of A_Date)

* if A_Date and B_Date are different, then the following should happen

insert one record to TABLE02 as A_ID,B_ID, A_Value, 0 , A_Date

insert another record to TABLE02 as A_ID,B_ID, 0 , B_Value, B_Date

 

(As you can see, when the date differs we enter the single record of Table 01 into 2 recoerds in table 02. the Value column and Date column are related in such a way that when A's date is entered, the value for B should be 0 and vise versa..)

 

i tried having a UDF but in halfway remembered that we cannot include INSERTS in UDFs..

can anyone please explain me how can i solve this problem ??

 

PS: For your reference , i've sketched a diagram. please click on this link to view it for further clarifications

http://i54.tinypic.com/eq6p7t.png

 

thanks in advance

-novicedba :)


How to Pass Values Between Web Pages ASP.NET

  
You can pass information between pages in various ways, some of which depend on how the redirection occurs. The following options are available even if the source page is in a different ASP.NET Web application from the target page, or if the source page is not an ASP.NET Web page:

Use a query string.

Get HTTP POST information from the source page.

The following options are available only when the source and target pages are in the same ASP.NET Web application.

Use session state.

Create public properties in the source page and access the property values in the target page.

Get control information in the target page from controls in the source page.

How to Pass Values Between ASP.NET Web Pages

  
You can pass information between pages in various ways, some of which depend on how the redirection occurs. The following options are available even if the source page is in a different ASP.NET Web application from the target page, or if the source page is not an ASP.NET Web page:

Use a query string.

Get HTTP POST information from the source page.

The following options are available only when the source and target pages are in the same ASP.NET Web application.

Use session state.

Create public properties in the source page and access the property values in the target page.

Get control information in the target page from controls in the source page.

jquery autocomplete multiple values

  

i got some samples and i did autocomplete using jquery , its working well for single input values

but i need to pass multiples values after one by one in the textbox. Is it possible to pass multiple

values in the textbox for autocomplete in jquery in asp.net?

 


JQGrid Loading deleted values

  

Hi,

This is quite strange. here is the issue:

Some Info:

1. I'm using a multi-select jqgrid.

2. I have my own delete button to delete multiple orders

The problem:

When i press the delete button on the pager of my jqgrid, the records are deleted from the database but JqGrid shows some records (4-5). On refreshing the grid, correct numbers of records are shown.


Here is the code:


function delorder() {
        var amg = $("#horder").getGridParam('selarrrow');
        var cont = amg.length;
        if (amg.length > 0) {

How to cast integer values as an array of enum values?

  

Hello all!

I'm working with VS2010 Beta2, ASP.NET and Dynamic Data. I'm using VB but will certainly be happy to receive a C# example if necessary. Laughing

I used a few of Steve's examples (Writing Attributes and Extension Methods for Dynamic Data and Dynamic Data - Hiding Columns in selected PageTemplates) to create a custom property attribute to be applied to a dynamic data column and want it to accept an array of enum values (each value will represent a dynamic data page template where this column should not be displayed).  My new attribute works fine when I hardcode it like this, meaning the HideColumnIn attribute is properly populated with the array of enum values:

<HideColumnIn(PageTemplate.List, PageTemplate.Edit)> _
Public Property My_DD_Column As Object

 

However, I want to store the values to be used for the HideColumnIn in the DB as integer values that correspond to the

Passing values in pages

  

Hi! Friends..

how to pass the value from one page to another page in asp.net  with out Using State Management Concepts?

Like 1. cookies

        2.Session

        3. QueryStrings

     With out using the above should pass the values...


how to bind Dropdownlist based on textbox values

  

hi

I have one drodownlist which show data based om textbox values...

Let us consider i have 

Select Name from table1 where Type IN(@typ)

here @typ is textbox values

here for example textbox will have some thing like this L1,L2,L3..

How to filter Name based and shown in drodownlist based on this L1,L2,L3(on textbox)..

Help me in this


Unable to get all the values from a field

  

Am reading an XML from web service and storing in  a dataset. 
then in write to a DataTable as follows

 DataTable dtResult1 = dsSearch.Tables["RESULTSET"];    
 DataTable dtHIT = dsSearch.Tables["HIT"];     
 DataTable dtField = dsSearch.Tables["FIELD"]; 

The issue  is  in the DataTable dtField i can only see 3 columns FieldID,Name,HIT_ID

The corresponding values in the dataTable looks like this for the corresponding fileds

0,rank,0
1,internalid,0
2,contentid,0
3,contentids,0
4,collection,0 

I am unable to get the Field Name values 1,8799f4646b6ed9acde142581a84f75a6 ,234B5F5F-F247-4EB6-9E39-A7B64C7FE1BD,Yes...etc

What would be the cause for this...Any Help

Below is the structure of the XML-


- <RESULTSET FIRSTHIT="1" LASTHIT="10" HITS="10" TOTALHITS="46" MAXRANK="3159" TIME="0.0040"> 
- <HIT NO="1" RANK="2955" SITEID="0" MOREHITS="0" FCOCOUNT="0"> 
<FIELD NAME="rank">1</FIELD> 
<FIELD NAME="internalid">8799f4646b6ed9acde142581a84f75a6 </FIELD> 
<FIELD NAME="contentid">234B5F5F-F247-4EB6-9E39-A7B64C7FE1BD</FIELD> 
<FIELD NAME="contentids" /> 
<FIELD NAME="collection&

Retreiving XML tag values

  

Hi,


I'm new to xml.


Currently I'm using the SOAP service and MSXML2.ServerXMLHTTP40  to get data from a website.

To retrieve data I'm using the "responseText" method of the MSXML2.ServerXMLHTTP40 class.


My XML tree looks like this. ( part of the tree)


<dataID>0</dataID>
<projectName>100208_FC3_BY_RO_rza</projectName>
<chunkSize>0</chunkSize>
<minLat>47.8512912</minLat>
<maxLat>48.2469535</maxLat>
<minLong>11.6839167</minLong>
<maxLong>12.4439732</maxLong>
<minTimestamp>2010-02-03T10:58:29</minTimestamp>
<maxTimestamp>2010-04-09T10:05:22</maxTimestamp>
<imageCount>154282</imageCount>
<audioCount>0</audioCount>
<gpsCount>84475</gpsCount>
<mcvCount>2475</mcvCount>
<fileCount>87</fileCount>
</JobInfo>


Just need to retrieve the value of the "projectName" & "dataID" from this.

Appreciate if somebody can help me to get the values of the above 2 fields with the relevant code.


Thanking you in advance.


reading values from config files in NUnit tests

  

One of my NUnit tests has to read in some values from config files.  In my main application this process works perfectly well, however when I run the unit test, the code that reads in the values from the config files doesnt read anything in.  Ive tried putting app.config in my unit test project (I even tried web.config) but nothing seems to work.  Are there any special steps involved when reading from config files in an nunit test ?


Passing HTML values from asp.net to asp

  

 We have a part of our website which is coded in classic asp. This takes the values of a login page (asp.net)  which uses 

<input type="text" /> to hold the values and then submit them to the asp page using the following line of code -

<input type="submit" value="Login" onClick="this.form.action='<%= SubmitURL() %>/login/login_user.asp?Type=Login&amp;this.form.encoding='application/x-www-form-urlencoded'; this.form.submit();" />

The asp page then retrieves the values using the code -

Value1 = Request.Form("Val1")

We now have a requirement to pre-populate the login values to provide an automated login process but don't want to change the older asp code. When we try to assign values to the input text in the asp.net page by assigning the value runat="server" the login fails as it does not seem to carry over when the page is submitted.

Is there a way where we can pre-populate the html textbox without making it unavailable to the asp page?

 


Cutting Edge: Comparing Web Forms And ASP.NET MVC

  

In this month's column, we'll explore the pros and cons of both ASP.NET Web Forms and ASP.NET MVC.

Dino Esposito

MSDN Magazine July 2009


Categories: 
ASP.NetWindows Application  .NET Framework  C#  VB.Net  ADO.Net  
Sql Server  SharePoint  Silverlight  Others  All   

Hall of Fame    Twitter   Terms of Service    Privacy Policy    Contact Us    Archives   Tell A Friend