Very Simple Getting Started Question About Formatting Data
Jan 2, 2008
Okay, I know this is a very simple question, but here it is.
I have a select statement that returns a value such as: 9902.7400000000.
In the select statement it just selecting Value. In the select statement, can I format the output to be with just two decimal places? I know I should know the answer to this and how to do it, but thank you for any help.
Does anyone familiar with a tool or a quick way to put apostrophes and commas around some values, so they could be used in a query ? Example, if I have a bunch of zip codes such as: 10001 10003 10009 54321 89043 etc Let's say I have a couple of hundreds of them. I need to be able to see them as -
I have been requested to take a number of columns and concatenate them into one column with a specifc format/layout. For example I need to take this, (noting all columns are of different datatypes:
col_1 col_2 col_3 col_4 col_5 col_6 col_7 PK #1 John Doe 123 Elm Street Anywhere NM 55660 #2 #3 etc..
...and create this on a different table (noting col_2 is of datatype "text": col_1 col_2 PK #1 John Doe 123 Elm Street Anywhere NM 55660 #2 #3 etc..
Can this type of formatting be done? I know how to concatenate data and use the convert function, but how do you add in CR-LF to get the proper formatting??
I am new to php/MySQL and am working on an online manual. The data is divided into Title and Content. The title is easy as it is one line but the content is meant to be in a number of paragraphs.
The Content field is currently set as "blob" and the text comes out as just one paragraph. Wha can I do to get paragraphs etc into the text?
I have a question about using FOR XML and sp_makewebtask. This (see below) is a simplified example where I have a table with 3 columns, the two first columns hold varius data and the third column (Subdata3) holds duplicated data.
My question is: Is it possible to transform the hierachy of data (see "Prefered XML output" for details) when transforming from SQL to XML using either FOR XML EXPLICIT or by using some sort of more advanced sp_makewebtask template (or some other technique perhaps)? And if, how? Any help welcome!
Cheers, Christian
----------------------
--- sp_makewebtask --- EXEC sp_makewebtask @outputfile = c: empoutput.xml, @query = 'SELECT Subdata1, Subdata2, Subdata3 FROM Data WHERE Subdata3 = X FOR XML AUTO, ELEMENTS', @templatefile ='c: emp emplate.tpl'
I'm looking for solutions to a formatting problem. I have two stand alone textboxes on a report body that I would like to have display side by side with very little white space between them.
Here is my problem. Simple concatenation of values into 1 textbox would work if the font size and font family were the same for both textboxes; unfortunately this isn't the case. The font size and family for each textbox is different. Is there a richtext control I can place on the report and load with preformatted rich text?
Hi, How would I convert(or format) money data type, so the output will be like: 123,456.78 or 12,345.67 (In other words how would I insert a comma which separates hundred from thousand...)
I am working with extracting data from a SAP database, and I would like to perform some 'visual formatting' on the returned data. Because the SQL code that I am writing will be used in a custom Report it is not possible for me to use '3rd Party' formatting tools. Furthermore because the database is hosted on an MS SQL 2008 R2 RDBMS it is not possible to use the IIF() function.
Here is a sample of the data that I am getting back at the moment. URL...Here is how I would like the data to be returned (with the exception that the blue lines will ideally be blank cells). URL...
I have come to believe that I should be using the ROW_NUMBER() function, along with the OVER() function and possibly the 'partition by' keywords.Here is my original code -
Code: select td.ItemCode as 'Item Code' , td.Dscription as 'Item Description', td.Quantity as 'Order Qty' , titm.OnOrder as 'PO Qty' , th.CardCode as 'BP Code', th.CardName as 'BP Name' , th.DocNum as 'Sales Order Number' , tsp.SlpName as 'Sales Person' , twhs.WhsCode as 'Whs Code' , isnull(tbloc.BINLABEL, '') as 'BIN Label', isnull(cast(tbloc.QUANTITY as nvarchar(20)), '') as 'BIN Qty'
code]...
Notice above that I only see the 'Seq' and no other data. How can I go about modifying this code so that I see all of the data columns I desire? If I further 'refine' the above, by adding case statements and the individual columns that I want to see (as opposed to using the * wildcard) I get a long list of error messages.
I need to return a single column (Name.company) but I want the data returned to be viewed in multiple columns.
First is that possible? Second if so how?
My data looks like this:
University X University X - 1 University X - 2 University X - 3 College X College X - 1 College X - 2 College X - 3 Cmty College X Cmty College X - 1 Cmty College X - 2 etc.
I have two questions : 1) Linking SQL Server Databases 2) Data Formatting like InputMask
1) I want to know if there is a way to link two seperate SQL server databases (it's tables) within the same server (local server). I created one Global database - with clients, etc. tables. The reason I did it like this is that I have to handle three seperate invoices databases, but using the same clients, etc. tables to get their information from. I used MS Access like this, linking Clients, etc tables from the Clients Database with the three other Databases. It worked fine but now I need some new features like setting the InvoiceNumber to something different, eg . 04/0001 for this year and then 05/0001 for next year. My Access databases can't change this numbers - it's just a autonumber I used. I know some Visual Basic code can make a change like perhaps adding a new column like InvYear and then adding it together with InvoiceNumber to get the Invoice Number, but I want to change it to SQL Server because I want to learn how SQL Server works. I am just starting out and not doing courses.
2) The other thing is I want to know if there is some feature in SQL Server to make data input easier, like a InputMask in Access where you can let a text column be formatted as you want. Eg. for a telephone number, it can store it in the format you made; like (011) 123 4567, not like you typed it : 0111234567.
I need to export some Database data into a text file. My Query looks like this:
SELECT Category1, Category2, Category3 FROM dbo.tbl1 WHERE Category1 = 'JP-4' AND Category2> 4;
This works fine to get the data, however there is some html formatting in the table entries such as
`<p>,</p>, ,</br>` etc.
So ideally I need to remove those when exporting the data to the text file. I've tried to do it with a simple replace query but that didn't work. I've also got an issue with line splits and would need to remove the ( ).
The Data format is something like this:
Category1: JP-4 Category2: 4 Category3:<p>Neque porro quisquam est qui dolorem ipsum quia dolor</p> <p>amet, consectetur, adipisci velit</p> Category4:<p>Neque porro quisquam est qui dolorem ipsum quia dolor</p>
I got it to work like this with the replace function:
SELECT REPLACE(REPLACE("PHOTOGRAPHS",'<p>',''),'</p>','') FROM dbo.khia_tbl WHERE Category1= 'JP-4' AND Category2> 4;
But the issue is that I've got 15 columns in total and that I need to do it for several different tags for each column so , </br>,
as well as "" and different spaces so that would be a lot and I thought there must be a better/more efficient way of doing it...
'17686568 - Bill Statement - 11/16/2006 - Stm. Date - 10/27/2006'
Above is the data string that I am trying to pull the information from. Here is the function I'm currently using:
cast(substring(c.itemname,charindex('Bill Statement - ',c.itemname)+18,10) as varchar)
...which gives me what i want most of the time, but beacuse the date is not equally formatted through out the database and the date can look like 5/4/2012 and using the above formula it will show up as 5/4/2012 -
So my question is how can i trim off the dash part when the data shows up like 5/4/2012 - ?
I have a report that has ten pages (essentially ten different reports). Each page has one, large main chart and then three smaller charts stacked on top of each other off to the right. The layout is in landscape. When I render the report in Reporting Services, the layout looks fine. If I export it to Adobe, it is also fine. However, when the report is emailed as a PDF attachment, the main chart on each page is completely missing. Has anybody experienced something simliar? I was having issues with the layout, and decreasing the height of each page fixed everything, but created this new problem. I am using Adobe 7.0. Thank you.
Please find below my query and result , how to display [Total Service Time ] in HH:Min format (Currently values in minutes)
Query: SELECT  DISTINCT  dbo.sectn_dept.sectn_sc AS Customer, MONTH(dbo.incident.date_logged) AS Month_Number, DATENAME(month, dbo.incident.date_logged) AS Month, YEAR(dbo.incident.date_logged) AS Year, dbo.incident.incident_ref PM_ref, dbo.product.product_n "Product",
[Code] .... Â Â Result: Need to Display [Total Service Time] in below Format:
I am attempting to update contact data that is displayed in a form. Unfortunately the followiing code that runs off the button click event does not seem to work or I am misssing something to make it fire. I get no errors but the data does not get updated. What am I missing? Thanks.Private Sub btn_Submit_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btn_Submit.Click Dim strConnection As StringDim cn As SqlConnection Dim sql As String strConnection = ConfigurationSettings.AppSettings("ConnectionString")cn = New SqlConnection(strConnection) sql = "UPDATE vw_BS_IssuerContacts SET ContactLastName = @ContactLastName, ContactFirstName = @ContactFirstName, ContactTitle = @ContactTitle, ContactEmail = @ContactEmail, ContactPhone = @ContactPhone, Address1 = @Address1, Address2 = @Address2, Address3 = @Address3, Country = @Country, ZipCode = @zipCode, AccessLevel = @AccessLevel WHERE IssuerCode = @IssuerCode"Dim UpdateCommand As New SqlCommand(sql, cn) UpdateCommand.Connection = cn UpdateCommand.CommandText = sqlUpdateCommand.Parameters.Add(New SqlParameter("@IssuerCode", Lbl_IssuerCode.Text)) UpdateCommand.Parameters.Add(New SqlParameter("@ContactLastName", txt_Lname.Text))UpdateCommand.Parameters.Add(New SqlParameter("@ContactFirstName", txt_Fname.Text)) UpdateCommand.Parameters.Add(New SqlParameter("@ContactTitle", txt_title.Text))UpdateCommand.Parameters.Add(New SqlParameter("@ContactEmail", txt_Email.Text)) UpdateCommand.Parameters.Add(New SqlParameter("@ContactPhone", txt_Phone.Text))UpdateCommand.Parameters.Add(New SqlParameter("@Address1", txt_Address.Text)) UpdateCommand.Parameters.Add(New SqlParameter("@Address2", txt_Address2.Text))UpdateCommand.Parameters.Add(New SqlParameter("@Address3", txt_City.Text)) UpdateCommand.Parameters.Add(New SqlParameter("@Country", txt_Country.Text))UpdateCommand.Parameters.Add(New SqlParameter("@ZipCode", txt_zipCode.Text)) UpdateCommand.Parameters.Add(New SqlParameter("@AccessLevel", Lbl_currAccessLevel.Text)) 'UpdateCommand.Parameters.Add(New SqlParameter("@AccessLevel", SqlDbType.Char, 2).Value = txt_CurrAccessLevelSelectedValue))UpdateCommand.Parameters.Add(New SqlParameter("@UserName", txt_Username.Text)) UpdateCommand.Parameters.Add(New SqlParameter("@infopw", txt_pw.Text))UpdateCommand.Parameters.Add(New SqlParameter("@Company", txt_IssName.Text)) 'do the update cn.Open() UpdateCommand.ExecuteNonQuery()
Greetings all, I have two databases and need to transfer some data from one to the other based on the "employee_Number". "Table 1 and 2" both have a complete listing of employees but in "Table 1" certain columns are empty. I need to see if "Table 2" has got data in those columns and if yes import them to the "Table 1" based on the "Employee Number" What is the simplest way to do this. both are on SQl server. please Help
Hi,I am developing an ASP.NET app that uses SQL Server 2005.I have 1 single connection string to the database that is defined in my web.config.In my backend VB code in the App_Data folder ( and so not related to any aspx page ) , i wish to access my database.Here is the code I use: Dim query As New SqlDataSource query.ConnectionString = ConfigurationManager.ConnectionStrings("MainConnectionString").ConnectionString query.InsertCommand = "INSERT INTO myTable(data, time) VALUES (...) query.Insert() All i want to is whether this is the correct and fastest way to access my database. Is it ?? Thanks for your help,roxie
If I am trying to import data from an Access database into my tables via transact sql how and what are my first steps. I'm a newbie just trying to learn. Do I do via an insert statement and if so how do I do that. My SQL tables have no data in them and I would also have to make sure that can convert the datatypes from Access to SQL. Thanks in advance for anyhelp given.
So these are a couple different interpretations I've made of a statement that needs to return students name's with the OSOS field in the attendcode code column of the attendance table on todays date with an attendance.aperiod column equal to 4.
This first one returns no results at all when I should get about 7 rows or so.....
Select Student.name, attendance.studentid, attendance.attenddate, attendance.aperiod, attendance.attendcode from Attendance, Student where AttendDate >= DateAdd(Day, DateDiff(Day, 0, GetDate()), 0) And AttendDate < DateAdd(Day, DateDiff(Day, 0, GetDate()), 0) + 1 And aperiod = '4' And AttendCode = 'OSOS' AND student.name = Attendance.studentid
This one is returning all of the names in the database 6 times each.
Select Student.name, attendance.studentid, attendance.attenddate, attendance.aperiod, attendance.attendcode from Attendance, Student where AttendDate >= DateAdd(Day, DateDiff(Day, 0, GetDate()), 0) And AttendDate < DateAdd(Day, DateDiff(Day, 0, GetDate()), 0) + 1 And aperiod = '4' And AttendCode = 'OSOS' order by name
I think something is messed up with my WHERE control but I cant figure it out... Any help is greatly appreciated!
I am looking at building some very simple web pages that attach to a SQL Server database. They will just display simple data from predefined views on the SQL Server.
A link to examples would be fantastic. I have done similar before to attach to data from access. Its the connection and data retrieval I need help with.
I have a table similar to the following (XYZ). I would like to write a select statement that will return the count of the unique items for each user that also happen to be less than 1 year old. The less than one year old part is rather easy dateadd(year, -1, getdate()), but I seem to be having a hard time figuring out how to get my desired result without using subselects. Any help greatly appreciated. Thanks in advance - Dan.
I have a simple data control task that has an OLE source and OLE target.
the source is a SQL query that returns 200m records this is then written straight out to a table. I have used a data flow task so that I can chunk up the inserts rather than using a INSERT INTO.....SELECT FROM.
I have ran it multiple times and it hangs once it reaches 18,961,020 records.
there is no locking on the database and I have even restarted the SQL instance to ensure that there was nothing else contending for resource.
I have changed gthe buffer size and rows per buffer to 100m and 100,000. Now it hangs before the 18.9m mark presumably becuase of the increased buffer size.
I notice that the SELECT statement continues to clock up io and cpu cycles but the BULK insert process has gone.
I want to create a procedure where nextvisitdate is a cloumn for date so when I passed variable @nextvisitdate then which data type I have touse with it.
CREATE PROCEDURE sp_salesman_nextvisitdate
@salesman varchar (50), @nextvisitdate date (50)
As
Select * from Entry Form
WHERE
@salesman = salesman AND @nextvisitdate = nextvisitdate
Hi, all:I'm a newbie trying to understand the concept of referential integrity anddealing with Primary and Foreign Keys. I'm sure mine is a simple problem...I've created 3 tables as follows:MemberTable-----1 Member ID (Primary key)2 Member Name3 etc...FoodsTable-----1 Food ID (Primary key)2 Food NameMemberFoods-----1 Member ID (Foreign key)2 Food ID (Foreign key)Now, I've just learned about referential integrity and all that, and this ismy first foray into creating primary/foreign keys, linking tables, etc. (soI'm assuming the above tables are fine). What I don't understand is this:if I have a (checkbox) form from which members can choose their favoritefoods, how do I insert that data? For example:Food Form-----Which of these are your favorite foods:1) Steak2) Chicken3) Potatoes4) etc...If I want to insert, let's say, 'Steak' and 'Chicken', do I have to first doa query on my Foods table to retrieve the Food ID's for Steak and Chicken,and then do an "insert" using those ID's into my MemberFoods table? (I amusing the actual Food Names (not ID's) as values on my form.) If so, cansomeone please share the SQL for retrieving and then inserting?I don' t know...maybe I'm overcomplicating the issue, but it just seems likea lot of extra work to maintain a "linking table" of foreign keys.Thanks for the help.