Showing posts with label field. Show all posts
Showing posts with label field. Show all posts

Friday, March 30, 2012

Putting Multiple Field data in a report table cell

I'm using report designer and Visual Studio .net 2003. I have a table in the report and would like to put multiple field values in a single cell. Something along the lines of this in the cell: =Fields!Phone.Value, Fields!.Fax.Value.

I don't know how to seperate the values to get them to work in the same table cell. I've tried commas, semi colons, spaces, parens.

How would I do this?=Fields!Phone.Value & " " & Fields!Fax.Value should work.
|||Great that works!

One other question, if I put a symbol (comma, semicolon) in the between the ampersands, how do I get it to leave the cell blank if there is nothing stored in the fields?

For example, say I have =Fields!Phone.Value & ", " & Fields!Fax.Value in the cell but when there is no values for those fields the cell is ", ".|||=Fields!Phone.Value & ISNULL(Fields!Fax.Value,"",",") & Fields!Fax.Value should work?
Otherwise you can try using IIF.
|||I couldn't use IsNull because it says it is not decleared. I can use IIF, so the correct code is =Fields!Phone.Value & IIF(Fields!Fax.Value=nothing,"",",") & Fields!Fax.Value

Thanks for your help.

sql

Wednesday, March 28, 2012

Putting Date into SQL Server

I'm trying to put a date into a SQL Server table. The database field type is "smalldatetime". The variable dDate is type "date" and contains: 2/2/2006 (although I think Cdate actually converts it to: #2/2/2006#). When I run the following code the date in the database is always ends up being: 1/1/1900.

Dim cmd As SqlCommand = New SqlCommand("INSERT INTO MyTable(MyDate) " & _
"VALUES (" & dDate & ")", SqlConn)
daAppts.InsertCommand = cmd
daAppts.InsertCommand.Connection = SqlConn
daAppts.InsertCommand.ExecuteNonQuery()

Any other field types work fine, it's just dates that aren't working ?? Can someone please provide a code snippet showing me what I'm doing wrong??

Dates have to be single quoted:

Dim cmd As SqlCommand = New SqlCommand("INSERT INTO MyTable(MyDate) " & _
"VALUES ('" & dDate & "')", SqlConn)

For clarity, here is the problem part enlarged (with the added single quotes):

('" & dDate & "')


|||That worked. Thank you.|||

Dim cmd As SqlCommand = New SqlCommand("INSERT INTO MyTable(MyDate) " & _
"VALUES (@.dDate)", SqlConn)
cmd.parameters.add("@.dDate",sqldbtype.datetime).value=dDate
daAppts.InsertCommand = cmd
daAppts.InsertCommand.Connection = SqlConn
daAppts.InsertCommand.ExecuteNonQuery()

If you must continue to use string concatenation, atleast pass sql server dDate.ToString("s") as the string format. That will prevent any ambiguity of the format you are giving it. Otherwise you might be suprised when your program dies when you start playing with cultures, and SQL Server misinterprets that date.

Putting Data In Report Footer

Hi,
We have a field in our dataset which we want to appear in the footer
of each page in our report.
To do this, we have added a textbox to the body of the report and
reference this data in the footer using the following:
=ReportItems!site_code.Value
This works fine, except when the record overflows onto a second page.
When this happens, the value is printed as a blank on the second and
subsequent pages, until we come to print the next record.
Ideally, we'd like the value to be printed on each page of the report.
Does anyone know of a solution to this?No takers for this?
Seems like a limitation of the software.

putting a field into the pageheader section - how?

Hi
Is it possible to place a field (typically "sum" or "first") into the
Header. Simply placing it there causes a compile error.
Thanks
MikePlace "sum" or "first" in any of the textbox(say textbox10) in body section
Then use =ReportItems!textbox10.value in pageheader section
Ponnurangam
"Mike" <mike.cornell@.interactivesa.co.za> wrote in message
news:#AieSwPsEHA.2536@.TK2MSFTNGP11.phx.gbl...
> Hi
> Is it possible to place a field (typically "sum" or "first") into the
> Header. Simply placing it there causes a compile error.
> Thanks
> Mike
>

Putting a db field in report header

I need to put a field in the report header, i think the way to do it is to
put a hidden textbox in the body and reference it from the header, but i
dont know how to make the expresion for that, is that the correct way to do
it?, is there better way?got the answer from another post
thandks anyway
"Rodrigo Sánchez" <rodrigoss@.netshoreprogramming.com> escribió en el mensaje
news:uzmr7f9qEHA.2856@.TK2MSFTNGP10.phx.gbl...
> I need to put a field in the report header, i think the way to do it is to
> put a hidden textbox in the body and reference it from the header, but i
> dont know how to make the expresion for that, is that the correct way to
do
> it?, is there better way?
>|||Rodrigo:
How ARE you able to place field data in the report header?
Thanks!
"Rodrigo Sánchez" wrote:
> I need to put a field in the report header, i think the way to do it is to
> put a hidden textbox in the body and reference it from the header, but i
> dont know how to make the expresion for that, is that the correct way to do
> it?, is there better way?
>
>

Put multiple results in one field

Hi all,

I need to put multiple results in one field, but not sure how. Here's
some sample code:

select a.name,
a.accountnum,
a.ordernum,
(select itemid from items where items_ordernum = a.ordernum) as
Items
>From clients a

There's multiple instances of 'itemid' in 'items' with the criteria I
gave, so this generates an error. I want to instead have the item
numbers listed as just a list seperated by commas, so the results might
be this:

Name AccountNum OrderNum Items
John Smith 12345 0000234 1233, 1333, 4322
Mike Jones 43223 0000023 4322, 543

And so forth. Is there someway to loop through this sub-query and make
the results become a list?

Thanks --

rlanglyHow do I concatenate strings from a column into a single row?
http://www.aspfaq.com/show.asp?id=2529

AMB

--
Message posted via http://www.sqlmonster.com|||Why do you wish to destroy First Normal Form? You are supposed to do
display formatting in the front end and never in the database.sql

put inserted value into a parameter in a trigger

How would i get the value of a field that i just inserted and put that into a parameter, so that i could update another table.

This is the code that i used in the trigger that did not work:
@.field1 = select srcfield1 from inserted

Anyway here is the full code:

CREATE TABLE Source (srcID int IDENTITY, srcField1 nvarchar(50))
CREATE TABLE Destination (destID int IDENTITY, destField1 nvarchar(50))
go

CREATE TRIGGER tr_SourceInsert ON [dbo].[Source]
FOR INSERT
@.Field nvarchar(50) output
AS
SELECT @.Field1 = SELECT Field1 FROM inserted
UPDATE Destination
SET Field1 = @.Field
where destID = '1'
go

INSERT Source(srcfield1) VALUES ('A')
goBased on your sample, there are no rows in the destination table. There couldn't be anything to update.

Just FYI, you appear to be taking a "one row" approach to your trigger, This will fail the first time you insert multiple rows into the source table using a single SQL statement.

If you explain a bit more about what you are trying to do, I'd bet that someone here can help you, but I don't understand well enough to be much help yet.

-PatP|||Okay, i forgot the line of sql that inserted a row into the DESTINATION table. Here it is data in it.
INSERT Source(srcfield1) VALUES ('1')

And i got the trigger to work by changing the code to:
SELECT @.field1 = srcField1 from inserted

How would i change this to take a 'multiple row' that you refer to.

thanks.|||To allow for multiple row inserts, you'd do something like:CREATE TABLE Source (srcID int IDENTITY, srcField1 nvarchar(50))
GO

CREATE TABLE Destination (destID int IDENTITY, destField1 nvarchar(50))
go

CREATE TRIGGER tr_SourceInsert ON [dbo].[Source]
FOR INSERT AS

UPDATE d
SET d.Field1 = i.Field1
FROM inserted AS i
JOIN destination AS d
ON d.destID = '1'

RETURN
GO

INSERT Source(srcfield1) VALUES ('1')
GO

INSERT Source(srcfield1) VALUES ('A')
GOThis code still seems suspect for a trigger, since I can't fathom why you would always want to update the destination table this way. There may be a reason for it, but I'm skeptical.

-PatP

Monday, March 26, 2012

Pushing IMAGE from SQL CE onto SQL Server 2000

Hello!

We are trying to use RDA to Push an image field onto SQL Server 2000 from a mobile device, but are having problems. Does anyone have any experience with this? If so, maybe some sample code would be very much appreciated. (We have been struggling with this for a while).

byte[] imagearray = null;

string imagestring = "";

try

{

imagearray = (byte[])SQLCEDr.GetValue(SQLCEDr.GetOrdinal("CapturedImage"));

imagestring = System.Text.Encoding.Default.GetString(imagearray, 0, (imagearray.Length - 1));

}

catch (Exception ex)

{

MessageBox.Show(ex.Message);

}

sParameters = "'" + imagestring + "'" ;

try

{

rda.SubmitSql("EXEC sp_HH_WorkOrder_SuppliesUsed " + sParameters,scon);

}

Thanks,

Andy

Here’s the problem:

imagestring = System.Text.Encoding.Default.GetString(imagearray, 0, (imagearray.Length - 1));

This line would be valid for an array which contains text in the default encoding. But it contains binary image data which would be treated as text, corrupted and lost.

To insert/retrieve binary data you have to use parameterized query. In fact, you should use parameterized queries for everything - would save you lot of troubles with localization (e.g. infamous 10/25/2006 vs. 25.10.2006) and formatting not to mention more secure and better performing code. If you don't know how to use parameters, please look it up on MSDN or search this forum as it's been answered before.

Wednesday, March 21, 2012

Purge

Hi Everyone.

i have a big database and for each table i have Active field (N/Y) and i wanna delete all record the active N. how i can do that without delete from each tables and looking to details tables before. our database have a complex relations.

please any solution.

thanks alot.

There is no simple way. You will have to scan through the entire database and execute 'delete

' for each desired table. Since you're doing data scrubbing, it might be simpler to use DTS/SSIS to extract desired data (i.e. Y rows) from every table into new table(s). Recreate constraints as needed after that. Else you will have to track down all all referenced/referencing tables and delete accordingly.

This little old script should help finding the ref tables.

Code Snippet

if object_id('usp_findreferences','p') is not null
drop proc usp_findreferences
go

create procedure usp_findreferences
/**************************************************************************-*
*/
/* Purpose: A quick & dirty way to find ref. objects for a[ll] table[s] */
/* Author: OJ Ngo */
/* Date: 02/28/2002 */
/**************************************************************************-*
*/
@.tbname sysname=null
as
set nocount on

Print 'Referenced:'
select c1.table_name,
c1.column_name,
fkey=r.constraint_name,
referenced_parent_table=c2.table_name,
c2.column_name
from information_schema.constraint_column_usage c1 join
information_schema.referential_constraints r on
c1.constraint_name=r.constraint_name
join information_schema.constraint_column_usage c2 on
r.unique_constraint_name=c2.constraint_name
where c1.table_name=coalesce(@.tbname,c1.table_name)
order by case when @.tbname is null then c1.table_name else c2.table_name end

print ''
print 'Referencing:'
select c1.table_name,
c1.column_name,
fkey=r.constraint_name,
referencing_child_table=c2.table_name,
c2.column_name
from information_schema.constraint_column_usage c1 join
information_schema.referential_constraints r on
c1.constraint_name=r.unique_constraint_name
join information_schema.constraint_column_usage c2 on
r.constraint_name=c2.constraint_name
where c1.table_name=coalesce(@.tbname,c1.table_name)
order by case when @.tbname is null then c1.table_name else c2.table_name end
go

|||

A some help can be get from "ON DELETE {CASCADE | NO ACTION |SET DEFAULT | SET NULL} " , the option of referential constraints.But for that you have to review the relationshisps of your db. You can be helped by "Database Diagrams" in Management Studio.

Tuesday, March 20, 2012

Pulling a unique field w/ join

Hi,

I'm trying to pull some data from two tables, and I need the data where a particular field is unique. Here's what I have right now:

SELECT tblTrip.*, tblTDYTravel.* FROM tblTrip
INNER JOIN tblTDYTravel ON tblTrip.TripID = tblTDYTravel.TripID
WHERE tblTrip.EmployeeID = @.EmployeeID
ORDER BY TangoID ASC

I need to get only the entries where the TangoID field is unique. Any ideas?

Thanks!What table is TangoID in?

blindman|||Originally posted by blindman
What table is TangoID in?

blindman

tblTrip|||Originally posted by Tarkon
Hi,

I'm trying to pull some data from two tables, and I need the data where a particular field is unique. Here's what I have right now:

SELECT tblTrip.*, tblTDYTravel.* FROM tblTrip
INNER JOIN tblTDYTravel ON tblTrip.TripID = tblTDYTravel.TripID
WHERE tblTrip.EmployeeID = @.EmployeeID
ORDER BY TangoID ASC

I need to get only the entries where the TangoID field is unique. Any ideas?

Thanks!

Use group by and aggregate functions.|||Originally posted by snail
Use group by and aggregate functions.

You uh, mind being a little more specific?|||This should do what you SAID you want (only unique tangoIDs):

SELECT tblTrip.*, tblTDYTravel.*
FROM tblTrip
INNER JOIN tblTDYTravel ON tblTrip.TripID = tblTDYTravel.TripID
INNER JOIN (select TangoID From TBLTrip group by TangoID Having count(*) = 1) UniqueTangoIDs
on tblTrip.TangoID = UniqueTangoIDs.TangoID
WHERE tblTrip.EmployeeID = @.EmployeeID
ORDER BY tblTrip.TangoID ASC

..whether this is what you MEAN you want is another story.

blindman

Monday, March 12, 2012

Pull only numeric values

I have a varchar field that contains both numeric and text data. I need to pull only numeric, non-null values.

I am fairly new to SQL, so I applogise if this is a really basic question.

Thanks.

hi

try:

SELECT col1, col2
FROM table
WHERE (ISNUMERIC(col1) AND col1 IS NOT NULL)

where col1 is your varchar column

Pull if matches 2nd to end of text field

I have 2 tables in a database. Table 1 has a field (1a) that contains a
customer part number. It also has a field (1b) that contains just a
manufacturer part number.
Table 2 contains 2 fields. Field (2a) has the description that might have a
word or many words then the manufacturer part number and then a
manufacturer. Field (2b) would have only have an internal number.
I am trying to match up the customer part number from table 1 to the
internal part number of table 2. Is there any way to do this?
The other task that I will need to do is pull the manufactuer and the
manufacturer part number out into seperate fields.
Thanks for your help in advance
DanOn Thu, 16 Feb 2006 21:35:38 -0500, "Dan" <danrev99@.yahoo.com> wrote:

>I have 2 tables in a database. Table 1 has a field (1a) that contains a
>customer part number. It also has a field (1b) that contains just a
>manufacturer part number.
>Table 2 contains 2 fields. Field (2a) has the description that might have a
>word or many words then the manufacturer part number and then a
>manufacturer. Field (2b) would have only have an internal number.
>I am trying to match up the customer part number from table 1 to the
>internal part number of table 2. Is there any way to do this?
>The other task that I will need to do is pull the manufactuer and the
>manufacturer part number out into seperate fields.
>Thanks for your help in advance
>Dan

>I am trying to match up the customer part number from table 1 to the
>internal part number of table 2. Is there any way to do this?
Are you familiar with SQL at all? This would be done with a JOIN:
SELECT *
FROM Tbl1 as T1
JOIN Tbl2 as T2
ON T1.CustPartNbr = T2.InternalNumber

>The other task that I will need to do is pull the manufactuer and the
>manufacturer part number out into seperate fields.
Look up the SUBSTRING and CHARINDEX.
Roy|||Why yes Roy I do know some about SQL. I understand that if the fields were
equal then this would work great. My problem is that table 1 field (1a)
manufacturer part number will match the just a part of table 2 field (2a)
part description. the "=" will not work
"Roy Harvey" <roy_harvey@.snet.net> wrote in message
news:kfgav1dde8i0e2imndpmssg95n04lbavvj@.
4ax.com...
> On Thu, 16 Feb 2006 21:35:38 -0500, "Dan" <danrev99@.yahoo.com> wrote:
>
>
> Are you familiar with SQL at all? This would be done with a JOIN:
> SELECT *
> FROM Tbl1 as T1
> JOIN Tbl2 as T2
> ON T1.CustPartNbr = T2.InternalNumber
>
> Look up the SUBSTRING and CHARINDEX.
> Roy|||I guess I misunderstood the question the first time around. When you
said that "I am trying to match up the customer part number from table
1 to the internal part number of table 2" thought that meant they were
matching values. Looking again, I think that you meant to match them
up by way of the manufacturer part number.
If that is the case, the first thing is to isolate the manufacturer's
part number in description field of the second table. Can you post
some examples of what this column looks like? It sounds like there
isn't much predictability to the position of the manufacturer's part
number, so this could get "interesting". Without seeing the data I
can only speculate, but I would guess it will require a few passes and
some temorary columns or perhaps a work table before we are through.
Roy
On Thu, 16 Feb 2006 21:35:38 -0500, "Dan" <danrev99@.yahoo.com> wrote:

>I have 2 tables in a database. Table 1 has a field (1a) that contains a
>customer part number. It also has a field (1b) that contains just a
>manufacturer part number.
>Table 2 contains 2 fields. Field (2a) has the description that might have a
>word or many words then the manufacturer part number and then a
>manufacturer. Field (2b) would have only have an internal number.
>I am trying to match up the customer part number from table 1 to the
>internal part number of table 2. Is there any way to do this?
>The other task that I will need to do is pull the manufactuer and the
>manufacturer part number out into seperate fields.
>Thanks for your help in advance
>Dan