Showing posts with label string. Show all posts
Showing posts with label string. Show all posts

Wednesday, March 28, 2012

How do I link two different field lengths with the same data

Hi,
In Crystal Reports 8.5, I am linking one file to another but do not get report data. The reason is the fields I am using to link one string is 4 characters while the other is 6. Is there a way to get two fields containing the same data in different files but wth different field lengths to link. thank youBump. This post is old, but I'm needing to do basically the same thing. I've got Crystal Reports 11.

Thanks

Friday, March 23, 2012

How do I insert a string value with quotes into a nvarchar column

I am reading data from another data source and storing it in the sqlce database. Some of the string values I'm trying to insert into the database have single quotes in the string (i.e. Johnny's Company). When I try to insert the values with the single quotes, it throws an exception. The code I use to insert the records is as follows:

cmd.CommandText = "INSERT sy_company " +

" (company_id, company, co_name, companyid) " +

"VALUES(" +

"'" + dtSYCompany.Rows[x]["company_id"] + "'," +

"N'" + dtSYCompany.Rows[x]["company"] + "'," +

"N'" + dtSYCompany.Rows[x]["co_name"] + "'," +

"'" + dtSYCompany.Rows[x]["companyid"] + "')";

cmd.ExecuteNonQuery();

When the company name (co_name) has a single quote in it, I get the error. How do I write the insert statement so it will work even though the value being inserted into co_name has a single quote in it?

Thanks so much!

Use parameters. It’s also great for performance and security.

By the way, it appears you’re using DataTable. In that case you could use DataAdapter.Update() instead of running commands manually. CommandBuilder can generate parametrized command for you.

|||That did it!!! Thanks so much.

Monday, March 19, 2012

How do I get SQL Server version (numbers only) programatically

Hi
I want to get SQL Server version. I know this way: Select @.@.version
But this gives me a very long string, i.e.
Microsoft SQL Server 2000 - 8.00.194 (Intel X86) Aug 18 2006
00:57:48
Copyright (c) 1988-2000 Microsoft Corporation Personal Edition on
Windows
NT 5.0 (Build 2195: Service Pack 4)
i want this value in a c++ application, and depending upon that i have
to fire query.
I just want the the major version number 6.0 ,7.0 , 8.0 or whatever
maybe.
How do I get these numbers only?
Regards,
Ravi ShankarFor the more recent versions of SQL Server, you can use SELECT
SERVERPROPERTY('ProductVersion'). Otherwise, you'll need to parse the
@.@.VERSION string. Transact-SQL example:
DECLARE @.Version nvarchar(125)
IF SERVERPROPERTY('ProductVersion') IS NOT NULL
BEGIN
SELECT SERVERPROPERTY('ProductVersion')
END
ELSE
BEGIN
SET @.Version =
SUBSTRING(@.@.VERSION, CHARINDEX('- ',
@.@.VERSION) + 2, 13)
SET @.Version = LEFT(@.Version, CHARINDEX(' ',
@.Version))
SELECT @.Version
END
Hope this helps.
Dan Guzman
SQL Server MVP
<ravidhari@.gmail.com> wrote in message
news:1156937494.514331.282750@.m73g2000cwd.googlegroups.com...
> Hi
> I want to get SQL Server version. I know this way: Select @.@.version
>
> But this gives me a very long string, i.e.
>
> Microsoft SQL Server 2000 - 8.00.194 (Intel X86) Aug 18 2006
> 00:57:48
> Copyright (c) 1988-2000 Microsoft Corporation Personal Edition on
> Windows
> NT 5.0 (Build 2195: Service Pack 4)
> i want this value in a c++ application, and depending upon that i have
> to fire query.
> I just want the the major version number 6.0 ,7.0 , 8.0 or whatever
> maybe.
> How do I get these numbers only?
>
> Regards,
> Ravi Shankar
>|||SELECT SERVERPROPERTY('ProductVersion')
Cheers,
Paul Ibison SQL Server MVP, www.replicationanswers.com|||Ravi,
You can try using "exec master..xp_msver".
It will return a recordset containing lots of info about your SQL Server
installation. One of the records will contain information about the
"ProductVersion".
Cheers!
SQLCatz

How do I get SQL Server version (numbers only) programatically

Hi
I want to get SQL Server version. I know this way: Select @.@.version
But this gives me a very long string, i.e.
Microsoft SQL Server 2000 - 8.00.194 (Intel X86) Aug 18 2006
00:57:48
Copyright (c) 1988-2000 Microsoft Corporation Personal Edition on
Windows
NT 5.0 (Build 2195: Service Pack 4)
i want this value in a c++ application, and depending upon that i have
to fire query.
I just want the the major version number 6.0 ,7.0 , 8.0 or whatever
maybe.
How do I get these numbers only?
Regards,
Ravi ShankarFor the more recent versions of SQL Server, you can use SELECT
SERVERPROPERTY('ProductVersion'). Otherwise, you'll need to parse the
@.@.VERSION string. Transact-SQL example:
DECLARE @.Version nvarchar(125)
IF SERVERPROPERTY('ProductVersion') IS NOT NULL
BEGIN
SELECT SERVERPROPERTY('ProductVersion')
END
ELSE
BEGIN
SET @.Version = SUBSTRING(@.@.VERSION, CHARINDEX('- ',
@.@.VERSION) + 2, 13)
SET @.Version = LEFT(@.Version, CHARINDEX(' ',
@.Version))
SELECT @.Version
END
--
Hope this helps.
Dan Guzman
SQL Server MVP
<ravidhari@.gmail.com> wrote in message
news:1156937494.514331.282750@.m73g2000cwd.googlegroups.com...
> Hi
> I want to get SQL Server version. I know this way: Select @.@.version
>
> But this gives me a very long string, i.e.
>
> Microsoft SQL Server 2000 - 8.00.194 (Intel X86) Aug 18 2006
> 00:57:48
> Copyright (c) 1988-2000 Microsoft Corporation Personal Edition on
> Windows
> NT 5.0 (Build 2195: Service Pack 4)
> i want this value in a c++ application, and depending upon that i have
> to fire query.
> I just want the the major version number 6.0 ,7.0 , 8.0 or whatever
> maybe.
> How do I get these numbers only?
>
> Regards,
> Ravi Shankar
>|||SELECT SERVERPROPERTY('ProductVersion')
Cheers,
Paul Ibison SQL Server MVP, www.replicationanswers.com|||Ravi,
You can try using "exec master..xp_msver".
It will return a recordset containing lots of info about your SQL Server
installation. One of the records will contain information about the
"ProductVersion".
Cheers!
SQLCatz

Monday, March 12, 2012

How do i get Data Type of Each Column in a Sqldatasource control?

Let's say... the sqldatasource has 3 columns: TableKey(int), TableName(string) and StartDate(datetime) and i'm writing a method to return the data type based on the column name.. for example: GetDataType("StartDate") should return "datetime"...what should i do?

I think this is what you need:http://www.java2s.com/Code/VB/Database-ADO.net/GetColunmDatatype.htm

Good luck.

|||

Thanks.

Wednesday, March 7, 2012

How do I extract data from selected rows from my excel source file?

The columns in my excel source contain data of different types with the column name being a string and the data in those columns being integers. Is there any way to only extract numeric data , in short I want column names to be omitted. Also the data is distributed unevenly , beggining at various rows in each column.

Thanking in advance :)

You can try to create a named range in the Excel sheet and then import only the range.

HTH.

|||Is there any other way to do it , like writing a query or so? I need help as i'm new to SSIS , any help would be appreciated

Friday, February 24, 2012

How do I do "If statement" in SSIS?

I need to get value from one table and if it is (for example) string - TodayDate, I need to change it to "Today Date" with a space in it and use it later in my Data Flow.

So I would need something similar to

If value = "TodayDate" Then

value - "Today Date"

Else

.....

How do I do that?

Thanks.

Check on the Derived Column transform in SSIS dataflow task.

|||

To add to Wenyang's answer...you will need to use the Conditonal Operator within the Derived Column transform.

? : (Conditional) (SSIS)

(http://msdn2.microsoft.com/en-us/library/ms141680.aspx)

Wenyang, I don't thinkyour answer is complete. Do you really think it warrants being marked as an answer? Hope you don't mind me asking.

Regards

Jamie

|||

How do I create expresiion?

Column Name - MonitorType

MonitorType ? "SA" : @.MyVariable

This shows error.

I want to see if the MonitorType field returns "SA" and if yes - use the variable I have.

If it returns for example "BA" use another variable.

|||

Vita wrote:

How do I create expresiion?

Column Name - MonitorType

MonitorType ? "SA" : @.MyVariable

This shows error.

I want to see if the MonitorType field returns "SA" and if yes - use the variable I have.

If it returns for example "BA" use another variable.

MonitorType == "SA" ? @.[MyVariable] : @.[SomeOtherVariable]

-Jamie

|||

Thanks.

|||Please don't forget to mark posts as answered.|||

What if I have more than 2 variables.

If "SA" - var 1,

If BA" - var 2

If "DA" - var 3

If "DS" - var 4

Can I do Else If in the same expression?

|||

I believe you can continue to add additional tests in the Derived Column task.

Rob

|||

Vita wrote:

What if I have more than 2 variables.

If "SA" - var 1,

If BA" - var 2

If "DA" - var 3

If "DS" - var 4

Can I do Else If in the same expression?

Yes. You need to nest the Conditonal Operator.

MonitorType == "SA" ? @.var1 : (MonitorType == "BA" ? @.var2 : (MonitorType == "DA" ? @.var3 : (MonitorType == "DS" ? @.var4 : @.SomeDefaultVariable)))

-Jamie

please don't forget to mark as answered.

|||Thanks again. I appreciate it.