T-SQL (SS2K8) :: Replacing String Values With Contents Of Variable

Dec 19, 2014

So I have the following column named String in a table:

<key>Children</key><integer>2</integer>

This of course can vary for the different records. What's the best way to replace the 2 with the contents of my variable with TSQL?

declare @children int
set @children = 4

I want to do something like this:

SELECT <key>Children</key><integer>@children</integer>

View 4 Replies


ADVERTISEMENT

Checking Contents Of Column And Replacing Contents If First Character Is A Letter

Jun 25, 2007

Hi All,I have come up against a wall which i cannot get over.I have an sql db where the date column is set as a varchar (i know, should have used datetime but this was done before my time and i've got to work with what is there). The majority of values are in the format dd/mm/yyyy. However, some values contain the word 'various'.I'm attempting to compare the date chosen on a c# .net page with the values in the db and also return all the 'various' values as well.I have accomplished casting the varchar to a datetime and then comparing to the selected date on the .net page. However, it errors when it comes across the 'various' entrant.Is there anyway to carry out a select statement comparing the start_date values in the db to the selected date on the .net page and also pull out all 'various' entrants at the same time without it erroring? i thought about replacing the 'various' to a date like '01/01/2010' so it doesn't stumble over the none recognised format, but am unsure of how to do it.This is how far i have got: casting the varchar column to datetime and comparing.  SELECT * FROM table1 WHERE Cast(SUBSTRING(Start_Date,4,2) + '/' + SUBSTRING(Start_Date,1,2) + '/' +SUBSTRING(Start_Date,7,4) as datetime)  '" + date + "'"Many thanks in advance! 

View 7 Replies View Related

Updating /replacing Contents Of The Table

Jun 11, 2007

Is it possible to do an update * where in we update all the contents of the table after selecting specific rows of the same table.

for ex:

create table #Result(rowid int identity(1,1),cust_no int,companyname varchar(100),address varchar(200),zip varchar(9));

insert into #Result(cust_no,companyname,address,zip)
where (customertype='r' and customer.comp_id ='11')
group by customer.cust_no, customer.company


select * from #Result where customerstatus='s';

after this i want to update/replace the #Result with whatever results I have from the select statment.

Thanks for your replies.

View 5 Replies View Related

T-SQL (SS2K8) :: Check Variable Values Dynamically

Nov 9, 2014

I have created dynamic sql to declare variables based on columns from the table and i set values to those variable now here is the issue . i want to check the variable values how do i do that dynamically

drop table test
create table test
(
id varchar(10) not null,
col1 varchar(10) ,
col2 varchar(10)

[Code] .....

Now my next step is verify if the variable is blank or not how do i do that ?

How do i verify all of the columns one after the other .

I am after the statement like this dynamically

-- IF NOT (@col1 = '') THEN set @SQL = @SQL + '[col1] = ' + @col1 + ' '
--IF NOT (@col2 = '') THEN set @SQL = @SQL + '[col2] = ' + @col2 + ' '

I need to check if the columns are blank or not dynamically as i do not want to hard code the column names there.

View 4 Replies View Related

T-SQL (SS2K8) :: Extract String - Variable Sizes With Breaks?

Jun 18, 2015

Row Value :

Fiscal Year: 2016(
)Budget Scenario: Main Budget (0+12)(
)Forecast Scenario: Jun (0+12) Forecast(
)Department: 400 - New York(
)YTD Period: Jun

and I need to extract 400 only... substring fails because the length of the Scenario, Forecast etc differs.

Should I just go for charindex on break() or is there a another way ?

View 3 Replies View Related

T-SQL (SS2K8) :: How To Cut Certain Values In A String To Separate Columns

Jun 5, 2014

I have a column containing values for different languages. I want to cut out the values per languate in a seperat column.

The syntax is a 2 letter country code followed by : the value is contained in double quotes. each languate is separated by a ; (except for the last one)

EX ur English, Dutch and Swedish:US:"Project/Prescription sale";NL:"Project/specificatie";SW:"Objektsförsäljning"

The result would Be
column header US
with value Project/Prescription sale

next column header NL
with value Project/specificatie etc.

Here are table examples:

IF OBJECT_ID('[#SALETYPE]','U') IS NOT NULL
DROP TABLE [#SALETYPE]

CREATE TABLE [#SALETYPE](
[SaleType_Id] [int] NOT NULL,
[name] [nvarchar](239) NOT NULL,

[Code] ....

View 9 Replies View Related

T-SQL (SS2K8) :: Finding Rows Where User Has Access To Contents But Not Record

Mar 27, 2014

I'm got a "folder" structure application which we'll be using as an in-house directory viewer. (In case you're wondering, it doesn't relate to any "real" folders, so using xp_cmdshell is out! )

Each folder and file record can have its own permissions, however these are assumed to inherit from the parent folder if no specific access rules have been set, basically in the same way file systems work. Each file record can only have one parent, and a folder can either have a parent or be at the root level.

Right now I'm having an issue with the inheritance of permissions. Say if I want to grant access to "Folder 1" to "Group A", then "Group B" shouldn't be able to see it. However, if I grant access to "File 1" in "Folder 1" to "Group B", then "Group B" should be able to see "Folder 1", but only see "File 1" and not the rest of the contents.

I thought I could do this with a CTE, but I'm having a bit of difficulty..

Here's the code:

CREATE TABLE #FileSystem (
FSIDINTEGER NOT NULL IDENTITY(1,1) PRIMARY KEY
,ParentFSIDINTEGER NULL
,NameVARCHAR(100)
,RecordTypeVARCHAR(1)-- (F)older, or Fi(L)e

[Code] ....

View 1 Replies View Related

Replacing Variable In Commandtext Fails?!?

Sep 12, 2006

Strangest thing is happening...Im building a select query..when I execute the query I get the results I want...But then I add the following code (yes am assigning the cmdText to myCommand etc, that all works):cmdText += "LookingForIDs LIKE '%,@LFID,%' "mycommand.Parameters.Add(New SqlParameter("@LFID", s(i)))(I used the debugger and this code is executed)the s() is an array of String.Now..I would expect that the @LFID part is replaced with the value of s(i)..in this case it's "2"Now when I execute the query...no results are found anymore....BUT when I execute the query in MS SQL Management Studio and replaced the @LFID manually with "2" it DOES work...and returns the right resultsAlso when I replaced the @LFID in the code with 2 so that it becomes:cmdText += "LookingForIDs LIKE '%,2,%' " it works....So my best guess is that for SOME reason the @LFID doesnt get replaced

View 4 Replies View Related

Integration Services :: SSIS Package - Replacing Null Values In One Column With Values From Another Column

Sep 3, 2015

I have an SSIS package that imports data from an Excel file, replaces any value in Excel that reads "NULL" to "", then writes the data to a couple of databases.

What I have discovered today, is I have two columns of dates, an admit date and discharge date column, and what I need to do is anywhere I have a null value in the discharge date column, I have to replace it with the value in the admit date column. 

I have searched around online and tried a few things using the Replace funtion in Derived columns but no dice so far. 

View 3 Replies View Related

Replacing Values

Nov 18, 2005

Hi i have 2 cols

col1 col2
A1 21
A2 22
A3 21
A4 23

I want to create a report such that i should see all values of col1 but in col2 i want to show only value of 21 and the remaining should be zero.
So basically all the other values except 21 should be zero in the report but should not be updated in the database.

So the report should look like

col1 col2
A1 21
A2 0
A3 21
A4 0

can you please tell me how to do that

Thanks
vic

Vicky

View 10 Replies View Related

T-SQL (SS2K8) :: Pivot Table - How To Get Right Count In First Data Mining Replacing Zeros

Mar 24, 2014

I run this code:

SELECT
Gruppo_Assegnatario,
[100] as stato1, [101] as stato2, [102] as stato3
FROM
(
select

[Code] ...

That extracts only zeros (columns "stato1", "stato2", "stato3"):

Gruppo_Assegnatariostato1stato2stato3
SDB_BE Vita Antiriciclaggio0 00
SDB_BE Vita Assistenza clienti000
SDB_BE Vita Emissione000
SDB_BE Vita Gestione Rendite000
SDB_BE Vita Liquidazioni000

[Code] ....

Unlike the "SourceTable":

select
CASE_ID_,
Stato,
Gruppo_Assegnatario
FROM TicketInevasiPerGruppoEStato
extracts

CASE_ID_ Stato Gruppo_Assegnatario
HD0000003736734 AssegnatoSDB_GBS Variazione
HD0000003736739 AssegnatoSDB_GBS Variazione
HD0000003736743 AssegnatoSDB_GBS Variazione
HD0000003736783 AssegnatoSDB_GBS Variazione
HD0000003736806 SospesoSDB_BE Vita Selezione

[Code] ....

How can I get the right count in the first data mining replacing the zeros (columns "stato1", "stato2", "stato3")?

View 5 Replies View Related

Extracting Contents Of Object Variable In Script Task

Feb 23, 2007

Hey Guys,

Im pretty new to Scripting in SSIS, but i have worked a fair bit out already, although i am stuck with the following problem.. If anyone can help out that would be great!!

Ok, i have a package that loops through records in a table, and extracts the detailed lines in a For Each loop. and stores them in a variable called DetailRecordSet with an data type of object.

I have a built a script task so that i can send out an email confirmation for each order, and i want to list the details in a HTML Table in the body of the message ( I have read that the standard send mail task wont support this, but found an example of using .NET code to generate the email message which will support it) .


What i want to know is how do i reference the columns in the Object variable so i can extract each line and add it into my string that i am creating with HTML codes.. I



e:( str = "<TABLE> <TR>" + Cstr(Variable for 1st column in recordset) + " </TR>"

if any can help my, that would be most appriciated.. Ive tried all different things that ive found on the net, but nothing is working.

Thanks in Advance

Scotty

View 3 Replies View Related

Sql Query Replacing Values

Apr 1, 2004

Hi, I have the following query.

sql = "select firstname AS Expr1, lastname AS Expr2, status AS Expr3 from person order by lastname"

Status is either 0,1,2 or 3

How can I use the query to create "a temp Alias" for the query, so that there is a "temp Alias" AS Expr4, AS Expr5, AS Expr6 and AS Expr7.

So if status = 0 then Expr4 = "true" else false
So if status = 1 then Expr5 = "true" else false
So if status = 2 then Expr6 = "true" else false
So if status = 3 then Expr7 = "true" else false

So when the reader reads Expr4 its either true or false.

Is this possible i a query?

View 1 Replies View Related

Replacing Field Values

Oct 9, 2007

I am trying to replace field values in SSIS. For exapmle, I have 'unkown' and 'N/A', and a few other values that mean the same thing, and I want to give all these fields the same value. I have not been able to find a tool in the toolbox to make this type of change. Is there one? And, if there is, do you know a link to a page explaining its use?

The closest I have come is the Derived column String Transformation:Replace. But, I have not been able to get this to do what I want. If you know of a good reference explaining this tool's use I'd appreciate it.

thanks much,

b2

View 4 Replies View Related

Replacing Null Values In Query

Jul 23, 2007

Hello,

I'm using the query wizard in VB.net to write a query for SQL CE. I want to replace null values with text. I expected the COALESCE function to do this but I get an error message saying its not a valid function. This is a sample.

Select COALESCE(table.Name,'No Name') as Name from table

Any help appreciated

Thanks

View 7 Replies View Related

Replacing Null Values With 0's In Matrix

Apr 13, 2007

Hi,



I am newbie to reporting services and I need some help. Could any one please let me know how to replace Null value with 0 in the data section of the Matrix. I don't want blanks to be displayed on the report, I want those to be replaced with 0's.



Thanks for your time.



View 4 Replies View Related

Replacing A Portion Of Text String In Column

Jul 20, 2005

I need to replace a portion of a url in a column as a result ofchanging servers. Is there a SELECT/REPLACE/UPDATE combination querythat can do this. The table has close to a thousand entries and wouldbe nice if a query can be set to do this. Tried the REPLACE examplein the BOOKS ONLINE but it creates syntax error, apparently because itdoes not like the characters in the url and/or wildcards. I don't needto replace the entire url, only the portion before ".com". Thanks inanticipation of your help.Pradip Sagdeo

View 3 Replies View Related

Formula For Replacing ENTER Key Inside A String

Mar 25, 2008

Hi guys,
I have a large text that can have some ENTER character inside of it. The problem is that the text must be inserted into a txt file in a single row. So what I need is to find those ENTER character and replace them with a space so as to have the whole string in one row.
How can I build that formula in derivide column?
Thanks for your help

View 10 Replies View Related

Removing Or Replacing Part Of A String In A Field?

Mar 4, 2008

Hi all I was wondering whether it was possible to remove or delete part of a String in a Field? Lets take for example I have:

- A Table called: Table_1
- A Field called: MyField
- MyField contains the value: Hello I am on the msdn forums

Is it possible to perform an UPDATE Query which deletes part of that sentence? If this was hard coded it would be rather simple but if the phrase was changing which would lead to the sentence also changing is it possible to do this?

Lets say I wanted to remove the part which said msdn forums. Then UPDATE the field again which should leave out the bit msdn forums.

Appreciate the responses, Onam.

View 5 Replies View Related

Replacing Values On A Left Outer Join

Apr 10, 2008

Hi all,

I have run into a problem that I am stuck on. I have 3 tables lets call them a,b, and c. What I want to do is left outer join a with b on a common value, then replace any null values in this result with a default value, and then left outer join table c on the previously joined table (on the columns that I just replaced certain values on).

please help!

Thanks

View 4 Replies View Related

SQL 2012 :: Replacing Column Names With Values

Nov 4, 2015

I have a field in a table that contains a different formula (varchar(1000)) for each record. It's along the lines of something like this, although each formula is different: ([ColumnA] - [ColumnB])/([ColumnC] - [ColumnD]). I plug that into a dynamic SQL statement so that it can get executed in a select statement.

Due to the variations of the formulas, checking for Divide by Zero, etc, we want to move this to a .NET method. We'd like to replace "ColumnA" and "ColumnB", etc., with the actual values so that we're passing something like (5-3)/(6-2). I haven't been able to figure out a way to do this without actually executing it. We don't want to pass the solution, but the equation filled with the actual values rather than the column names.

View 3 Replies View Related

Passing Around Message Contents As Streams (conversion To/from String &&amp; XmlDoc's).

Oct 2, 2006

More of a general "Streams" question than broker specific, but this is all being done in the context of Broker passing the messages around. The use of Streams & Encoding seems to be my problem and I'm not as familiar with Streams as I am with other areas of the Framework... Any advice would be appreciated.

At this point, I've created my own objects/stored procedures based loosely on the ServiceBrokerInterface class provided in the SQL Server samples. Some of this was done for simplification and as a learning exercise, but also to ensure that all of the SQL operations are being done via Stored Procedures and not inline SQL. This was done to adhere to our existing security policy used on this project.

In this "interface" I've built, I have a [BrokerMessage.cs] class which is meant to have a few additional pieces of functionality beyond what the MS provided version had supplied.

1st... A constructor for accepting either String or XmlDocument as the "content"

2nd... Methods to return either a XmlDocument or a simple String.

Since all of the Broker functionality is defined as using VARBINARY(MAX) in my stored procedures, I don't believe I have any problems at that level. It's simply a binary blob to Broker.

In my constructor for accepting String or XmlDocuments, I attempted to use the following...

public BrokerMessage(string type, XmlDocument contents)

{

m_type = type;

m_contents = new MemoryStream(EncodingProvider.GetBytes(contents.InnerXml));

}

My understanding was that MemoryStream is derived from Stream so I can implicitly cast it. The "EncodingProvider" is a static member set as follows:

public static Encoding EncodingProvider = Encoding.Unicode;

This way I ensure that internal & external code can all be set to use the same encoding and easily changed if necessary. I was hoping to avoid using Unicode since the rest of the application does not require it, but from my understanding all Xml documents in SQL Server are Unicode based, so this should be a better encoding choice for any processing that may potentially occur within SQL Server itself.

In my methods to return the various forms of the "Stream", I have the following code... The ToBytes() method is what is used to pass intot he stored procedure parameter that is defined as VarBinary and expecting a byte array. One area of concern is that the Read method accepts an INT for the length, but the actual Length property is a LONG. I'm sure there's a better way to handle this and I would welcome any advise there.



/// <summary>

/// Used to convert from a Stream back to a simple Byte array.

/// </summary>

/// <returns></returns>

public virtual byte[] ToBytes()

{

byte[] results = new byte[this.Contents.Length];

this.Contents.Read(results, 0, (int)this.Contents.Length);

return results;

}

/// <summary>

/// Used to convert from a Stream back to a simple String.

/// </summary>

/// <returns></returns>

public new string ToString()

{

byte[] buffer = this.ToBytes();

String results = EncodingProvider.GetString(buffer);

return results;

}

/// <summary>

/// Used to convert from a Stream back to a simple XmlDocument.

/// </summary>

/// <returns></returns>

public virtual XmlDocument ToXmlDocument()

{

XmlDocument results = new XmlDocument();

results.InnerText = this.ToString();

return results;

}



View 5 Replies View Related

SQL Server 2012 :: Replacing String (Particular Part Of A Row In A Table With New Value)

Oct 7, 2015

I'm trying to replace a particular part of a row in a table with a new value.

The row is called "DataPath" and it has a lot of values like so:

mashOperationsComponent Data FilesSantec

I want to run a query to replace the mash with our DFS namespace share name companysharesDepartments but keep everything else past the mash part of the original row.

I'm currently running this query, it says it is altering 30,000 rows, but it doesn't look like it's doing anything at all..

UPDATE dbo.Part
SET DataPath = REPLACE(DataPath,'company.localsharesDepartments','mash')
WHERE DataPath like 'mash\%'

So for example, it would change the mash above to

company.localsharesDepartmentsOperationsComponent Data FilesSantec

View 2 Replies View Related

Problem In Saving Page Contents I.e; Textbox And Dropdownlist Values Please Help

Feb 29, 2008

Hi all,please have a look of code i am unable to perform save operation onthe asp.net web page.I ahve written a stored procedure. the same code works if all aretextboxes, but some of textbox replaced with dropdownlist box thenthis save operation doesn't occurs. please let me know where is themistake in coding .vb.net code :- Protected Sub btnSave_Click(ByVal sender As Object, ByVal e AsEventArgs)        Dim employmentID As Integer =Request.QueryString("employmentID")        Dim resourceID As Integer = Request.QueryString("resourceID")        Dim projectID As Integer = Request.QueryString("ProjectID")        Dim dbconsave As SqlConnection        dbconsave = New SqlConnection(HRISDBConnectionString)        Dim dbcomsave As New SqlCommand("sp_save_NewHireEmailnotify",dbconsave)        dbcomsave.CommandType = CommandType.StoredProcedure        dbcomsave.Parameters.Add(New SqlParameter("employmentID",SqlDbType.Int))        dbcomsave.Parameters("employmentID").Value = employmentID        dbcomsave.Parameters.Add(New SqlParameter("resourceID",SqlDbType.Int))        dbcomsave.Parameters("resourceID").Value = resourceID        dbcomsave.Parameters.Add(New SqlParameter("ProjectID",SqlDbType.Int))        dbcomsave.Parameters("ProjectID").Value = projectID        dbconsave.Open()        dbcomsave.Parameters.Add("@PreferredFirstName",SqlDbType.VarChar)        dbcomsave.Parameters.Item("@PreferredFirstName").Value =txtPreferredFirstName.Text.ToString()        dbcomsave.Parameters.Add("@PreferredLastName",SqlDbType.VarChar)        dbcomsave.Parameters.Item("@PreferredLastName").Value =txtPreferredLastName.Text.ToString()        dbcomsave.Parameters.Add("@CellPhone", SqlDbType.VarChar)        dbcomsave.Parameters.Item("@CellPhone").Value =txtCellPhone.Text.ToString()        dbcomsave.Parameters.Add("@HomePhone", SqlDbType.VarChar)        dbcomsave.Parameters.Item("@HomePhone").Value =txtHomePhone.Text.ToString()        dbcomsave.Parameters.Add("@HomeAddressLine1",SqlDbType.VarChar)        dbcomsave.Parameters.Item("@HomeAddressLine1").Value =txtHomeAddressLine1.Text.ToString()        dbcomsave.Parameters.Add("@HomeAddressLine2",SqlDbType.VarChar)        dbcomsave.Parameters.Item("@HomeAddressLine2").Value =txtHomeAddressLine2.Text.ToString()        dbcomsave.Parameters.Add("@HomeAddressState",SqlDbType.VarChar)        dbcomsave.Parameters.Item("@HomeAddressState").Value =txtHomeAddressState.Text.ToString()        dbcomsave.Parameters.Add("@HomeAddressCity",SqlDbType.VarChar)        dbcomsave.Parameters.Item("@HomeAddressCity").Value =txtHomeAddressCity.Text.ToString()        dbcomsave.Parameters.Add("@HomeAddressZIP", SqlDbType.VarChar)        dbcomsave.Parameters.Item("@HomeAddressZIP").Value =txtHomeAddressZIP.Text.ToString()        dbcomsave.Parameters.Add("@HomeAddressCountry",SqlDbType.VarChar)        dbcomsave.Parameters.Item("@HomeAddressCountry").Value =txtHomeAddressCountry.Text.ToString()        dbcomsave.Parameters.Add("@ArrangementType",SqlDbType.VarChar)        dbcomsave.Parameters.Item("@ArrangementType").Value =ddlArrangementType.SelectedItem.ToString()        dbcomsave.Parameters.Add("@PracticeGroup", SqlDbType.VarChar)        dbcomsave.Parameters.Item("@PracticeGroup").Value =ddlPracticeGroup.SelectedItem.ToString()        dbcomsave.Parameters.AddWithValue("@EquipmentNeeds",txtEquipmentNeeds.Text.ToString())        Try            dbcomsave.ExecuteNonQuery()            lblMessage.Text = "Record saved successfully"        Catch ex As Exception        End Try        dbconsave.Close()    End Sub==============================================================================.aspx code :-<table>                                 <tr>                                    <td >                                        <asp:LabelID="lblPreferredFirstName" runat="server" Text="Name(Preferred FirstLast) :" ForeColor="Blue"></asp:Label>                                    </td>                                    <td                                        <asp:TextBoxID="txtPreferredFirstName" runat="server" Text="" BorderStyle="None"></asp:TextBox>&nbsp;&nbsp;                                        <asp:TextBoxID="txtPreferredLastName" runat="server" Text="" BorderStyle="none" ></asp:TextBox>                                    </td>                                </tr>                <tr>                                    <td >                                        <asp:Label ID="lblCellPhone"runat="server" Text="CellPhone :" ForeColor="Blue"></asp:Label>                                    </td>                                    <td >                                        <asp:TextBox ID="txtCellPhone"runat="server" Text="" ></asp:TextBox>                                    </td>                                </tr>                <tr>                                    <td >                                        <asp:Label ID="lblHomePhone"runat="server" Text="HomePhone :" ForeColor="Blue"></asp:Label>                                    </td>                                    <td >                                        <asp:TextBox ID="txtHomePhone"runat="server" Text="" ></asp:TextBox>                                    </td>                                </tr>                <tr>                                    <td >                                        <asp:LabelID="lblHomeAddressLine1" runat="server" Text="HomeAddressLine1 :"ForeColor="Blue"></asp:Label>                                    </td>                                    <td >                                        <asp:TextBoxID="txtHomeAddressLine1" runat="server" Text="" ></asp:TextBox>                                    </td>                                </tr>                                <tr>                                    <td >                                        <asp:LabelID="lblHomeAddressLine2" runat="server" Text="HomeAddressLine2 :"ForeColor="Blue"></asp:Label>                                    </td>                                    <td >                                        <asp:TextBoxID="txtHomeAddressLine2" runat="server" Text="" ></asp:TextBox>                                    </td>                                </tr>                                <tr>                                    <td >                                        <asp:LabelID="lblHomeAddressState" runat="server" Text="HomeAddressState :"ForeColor="Blue"></asp:Label>                                    </td>                                    <td >                                        <asp:TextBoxID="txtHomeAddressState" runat="server" Text="" ></asp:TextBox>                                    </td>                                </tr>                                <tr>                                    <td >                                        <asp:LabelID="lblHomeAddressCity" runat="server" Text="HomeAddressCity :"ForeColor="Blue"></asp:Label>                                    </td>                                    <td >                                        <asp:TextBoxID="txtHomeAddressCity" runat="server" Text="" ></asp:TextBox>                                    </td>                                </tr>                                <tr>                                    <td >                                        <asp:LabelID="lblHomeAddressZIP" runat="server" Text="HomeAddressZIP :"ForeColor="Blue"></asp:Label>                                    </td>                                    <td >                                        <asp:TextBoxID="txtHomeAddressZIP" runat="server" Text="" ></asp:TextBox>                                    </td>                                </tr>                                <tr>                                    <td >                                        <asp:LabelID="lblHomeAddressCountry" runat="server" Text="HomeAddressCountry :"ForeColor="Blue"></asp:Label>                                    </td>                                    <td >                                        <asp:TextBoxID="txtHomeAddressCountry" runat="server" Text="" ></asp:TextBox>                                    </td>                                </tr>                <tr>                                    <td >                                        <asp:Label ID="lblArrangement"runat="server" Text="Arrangement :" ForeColor="Blue"></asp:Label>                                    </td>                                    <td >                                        <asp:DropDownListID="ddlArrangementType" runat="server" Width="160px"DataSourceID="ObjectDataSourceArrangementType"DataTextField="ArrangementType" DataValueField="ArrangementType"OnDataBound="ddlArrangementType_DataBound">                                        </asp:DropDownList>                                        <%--<asp:TextBoxID="txtArrangement" runat="server" Text="" ></asp:TextBox>--%>                                    </td>                                </tr>                 <tr>                                    <td >                                        <asp:LabelID="lblPracticeGroup" runat="server" Text="Practice Group :"ForeColor="Blue"></asp:Label>                                    </td>                                    <td >                                        <asp:DropDownListID="ddlPracticeGroup" runat="server" Width="160px"DataSourceID="ObjectDataSourcePracticeGroup"DataTextField="PracticeGroup" DataValueField="PracticeGroup"OnDataBound="ddlPracticeGroup_DataBound">                                        </asp:DropDownList>                                        <%--<asp:TextBoxID="txtPracticeGroup" runat="server" Text="" ></asp:TextBox> --%>                                    </td>                                </tr></table>please help me to solve the issue.Thanks in advance 

View 3 Replies View Related

Displaying The Values That Dont Match And Replacing By NULL

Feb 6, 2003

Hi,

Im having a couple of problems with SQL.

I have this query...

SELECT Band.Name, Member.Name
FROM Member
JOIN MemberOf ON Member.Mid = MemberOf.Mid
JOIN Band On MemberOf.Bid = Band.Bid
WHERE MemberOf.Instrument = 'keyboards';

which basically shows me the name of the bands who had keyboard players. I would like it to also display the names of the band who didnt have keyboard players, replacing the keyboard players name with "NULL".

so... my questions are :)

how do u get it to display the records that do not match the condition, and how do u get it to replace the keyboard players name with "NULL" when they do not match the condition.

PS. The three tables are

Band. Which has Bid as a primary key.
Member. Which has Mid as a primary key.
MemberOf. Which links these through its two foreign keys Mid and Bid.

Thanks for your help! (assuming someone does)

View 2 Replies View Related

SQL Server 2012 :: Replacing Recurring Characters In A String With Single Character

Jan 20, 2014

I have a problem where I want to write a function to remove recurring characters from a string and replace them with a single same character.

For instance I have the string '12333345566689' and the result should be '12345689'. In Oracle I could do this with "regexp_replace('12333345566689', '(.)1+', '1')", but in T-SQL the only solution I could think of is something like this:

DECLARE @code NVARCHAR(255)
SET @code = '12333345566689';
SET @code = REPLACE(REPLACE(REPLACE(@Code, '1', '~1'), '1~', ''), '~1', '1');

and repeat this for 2 - 9. But I'm sure there is a more elegant version for this in SQL Server 2012.

View 9 Replies View Related

T-SQL (SS2K8) :: Count Number Of Values That Exist In A Row Based On Values From Array Of Numbers

Apr 16, 2014

How to count the number of values that exist in a row based on the values from an array of numbers. Basically the the array of numbers I want to look for are in row 1 of table [test 1] and I want to search for them and count the "out of" in table [test 2]. Excuse me for not using the easiest way to convey my question below. I guess in short I have 10 numbers and like to find how many of those numbers exist in each row. short example:

Table Name: test1
Columns: m1 (int), m2 (int), m3 (int) >>> etc
Array/Row1: 1 2 3 4 5 6 7 8 9 10

------
Table Name: test2
Columns: n1 (int), n2 (int), n3 (int), n4 (int), n5 (int)

Row 1: 3, 8, 18, 77, 12
Row 2: 1, 4, 5, 7,18, 21
Row 3: 2, 4, 6, 8, 10

Answer: 2 out of 5
Answer: 4 out of 5
Answer: 5 out of 5

View 2 Replies View Related

T-SQL (SS2K8) :: Dynamically Change Values In Script Based On 3 Values

Feb 27, 2014

I have a script that I use after some amount of data massaging (not shown). I would like to be able to change the

1) denominator value (the value 8 in line 32 of my code) based on how many columns are selected by the where clause:

where left(CapNumber,charindex('_', CapNumber)-1) = 1where capNumber is a value like [1_1], [1_4], [1_6]...[1_9] capNumber can be any values from [1_1]...[14_10] depending upon the specialty value (example: Allergy) and the final number after the equal sign is a number from 1 to 14)

2) I'd like to dynamically determine the series depending upon which values correspond to the specialty and run for each where: left(CapNumber,charindex('_', CapNumber)-1) = n. n is a number between 1 and 14.

3) finally I'd like to dynamically determine the columns in line 31 (4th line from the bottom)

If I do it by hand it's 23 * 14 separate runs to get separate results for each CapNumber series within specialty. The capNumber series is like [1_1], [1_2], [1_3],[1_4], [1_5], [1_6], [1_7], [1_8],[1_9]
...
[8_4],[8_7]
...
[14_1], [14_2],...[14_10]
etc.

Again, the series are usually discontinuous and specific to each specialty.

Here's the portion of the script (it's at the end) that I'm talking about:

--change values in square brackets below for each specialty as needed and change the denom number in the very last query.

if object_id('tempdb..#tempAllergy') is not null
drop table #tempAllergy
select *
into #tempAllergy
from
dbo.#temp2 T

[Code] ....

If I were to do it manually I'd uncomment each series line in turn and comment the one I just ran.

View 6 Replies View Related

T-SQL (SS2K8) :: Aggregate Monthly Values From Interval Values?

May 14, 2014

I want to aggregate to monthly values for the reading. I want to display Reading value for Oct 2010, November 2010 likewise My question is simple and I have tried to follow the etiquette.

Currently it is displaying.....

MeterIDReadingdateReading
3969 22/10/2013 0:150
3969 22/10/2013 0:300
3969 22/10/2013 0:450
3969 22/10/2013 1:000
3969 22/10/2013 1:150
3969 22/10/2013 1:300
3969 22/10/2013 1:450
3969 22/10/2013 2:001
3969 22/10/2013 2:150
MeterId int
ReadingDate datetime
Reading real

-===== If the test table already exists, drop it

IF OBJECT_ID('TempDB..#mytable','U') IS NOT NULL
DROP TABLE #mytable

--===== Create the test table with

CREATE TABLE #mytable
(
meterID INT PRIMARY KEY,
Readingdate DATETIME,
reading real
)

--===== Setup any special required conditions especially where dates are concerned

SET DATEFORMAT DMY
SELECT '4','Oct 17 2013 12:00AM','5.1709' UNION ALL
SELECT '4','Oct 17 2013 12:15AM','5.5319' UNION ALL
SELECT '4','Nov 17 2013 12:00AM','5.5793' UNION ALL
SELECT '4','Nov 17 2013 14:00AM','5.2471' UNION ALL
SELECT '5','Nov 17 2013 12:00AM','5.1177' UNION ALL
SELECT '5','Nov 17 2013 14:00AM','5.5510' UNION ALL
SELECT '5','Dec 17 2013 15:00AM','5.5128', UNION ALL
SELECT '5','Dec 17 2013 16:00AM','5.5758' UNION ALL

Output should display as

MeterId Period Reading

4 Oct 13 10.20
4 Nov 13 10.40
5 Oct 13 10.20
5 Nov 13 10.40
4 Dec 13 11.15

View 4 Replies View Related

Transact SQL :: Insert Values From Variable Into Table Variable

Nov 4, 2015

CREATE TABLE #T(branchnumber VARCHAR(4000))

insert into #t(branchnumber) values (005)
insert into #t(branchnumber) values (090)
insert into #t(branchnumber) values (115)
insert into #t(branchnumber) values (210)
insert into #t(branchnumber) values (216)

[code]....

I have a parameter which should take multiple values into it and pass that to the code that i use. For, this i created a parameter and temporarily for testing i am passing some values into it.Using a dynamic SQL i am converting multiple values into multiple records as rows into another variable (called @QUERY). My question is, how to insert the values from variable into a table (table variable or temp table or CTE).OR Is there any way to parse the multiple values into a table. like if we pass multiple values into a parameter. those should go into a table as rows.

View 6 Replies View Related

Transact SQL :: Convert Comma Separated String Values Into Integer Values

Jul 28, 2015

I have a string variable

string str1="1,2,3,4,5";

I have to use the above comma separated values into a SQL Search query whose datatype is integer. How would i do this Search query in the IN Operator of SQL Server. My query is :

declare @id varchar(50)
set @id= '3,4,6,7'
set @id=(select replace(@id,'''',''))-- in below select query Id is of Integer datatype
select *from ehsservice where id in(@id)

But this query throws following error message:

Conversion failed when converting the varchar value '3,4,6,7' to data type int.

View 4 Replies View Related

Transact SQL :: How To Get String Array In String Variable

Jul 28, 2015

I have a string variable and following data.

Declare @ServiceID varchar(200)
set @ServiceID='change chock','change starter','wiring for lights','servicing'

when I assign values in @ServiceID  in the above manner then it shows error. How to get string array in @ServiceID variable so that i can go ahead.

View 8 Replies View Related

SQL Server 2012 :: Replace All Values In String With Values From Look Up Table

Mar 19, 2014

I have a table that lists math Calculations with "User Friendly Names" that look like the following:

([Sales Units]*[AUR])
([Comp Sales Units]*[Comp AUR])

I need to replace all the "User Friendly Names" with "System Names" in the calculations, i.e., I need "Sales Units" to be replaced with "cSalesUnits", "AUR" replaced with "cAUR", "Comp Sales Units" with "cCompSalesUnits", and "Comp AUR" with "cCompAUR". (It isn't always as easy as removing spaces and added 'c' to the beginning of the string...)

The new formulas need to look like the following:

([cSalesUnits]*[cAUR])
([cCompSalesUnits]*[cCompAUR])

I have created a CTE of all the "Look-up" values, and have tried all kinds of joins, and other functions to achieve this, but so far nothing has quite worked.

How can I accomplish this?

Here is some SQL for set up. There are over 500 formulas that need updating with over 400 different "look up" possibilities, so hard coding something isn't really an option.

DECLARE @Synonyms TABLE
(
UserFriendlyName VARCHAR(128)
, SystemNames VARCHAR(128)
)
INSERT INTO @Synonyms
( UserFriendlyName, SystemNames )

[Code] .....

View 3 Replies View Related







Copyrights 2005-15 www.BigResource.com, All rights reserved