Showing posts with label description. Show all posts
Showing posts with label description. Show all posts

Wednesday, March 7, 2012

I need SQL Query Help

Sir,

We are try to insert query like this

Insert into Table_1 (smDate,Description) Values ('Thu, Feb 15, 2007 03:00 PM', ' Hai, It's Just for Testing')

This is Exact Query about this...

We know about MS ACCESS it has Built in function like Format('Thu, Feb 15, 2007 03:00 PM','mm/dd/yyyy HH:MM')

But I am new to SQL. I dont know the The Date Format built in function in SQL Server.

How can i Insert this Quesry to SQL Table

and also How can insert "it's " this type of words into SQL..

Can you help me

this is very helpful for my project

Thanks With Regards

S.Senthil Nathan

The quickest way i've used and seen being used to put an apostrophe into a SQL statment, is to do a replace on the string with a double quote, then you will need to do a reverse replace on the double quote back to an apostrophe, not the best way but one solution, the other is to escape the apostrophe with another so it would beit''sbut this would still require some parsing of the string.

Have a look at this artilce for working with formatting the date/time in SQL :http://sqljunkies.com/Article/6676BEAE-1967-402D-9578-9A1C7FD826E5.scuk

|||

For your date format issue, if you can remove the "Day, " from the date, you can insert the string you have. I.e. 'Feb 15, 2007 3:00 PM' is a valid date string and will be formatted automatically by SQL server according to how SQL server is set up. For example, if using the defaults on a US-based setup, SQL server formats the date like you requested.

if you need to insert something with single quotes, you have two options. First, you can replace it with two single quotes, i.e. 'it''s' would putit's in the database.

Second, you can use parameters. Your sql statement would be like "INSERT INTO dbo.MyTable (StringValue) Values (@.StringValue)", and then add a sql parameter to your sqlcommand as if you were using a stored procedure. If you had a Data.SqlClient.SqlCommand named command:

command.CommandType = Data.CommandType.Textcommand.CommandText = strSQL' this is your insert statement with a parametercommand.Parameters.AddWithValue("@.StringValue", "it's")
I prefer the second choice becuase it's easier than remembering to replace quotes and other sql syntax.

I need SQL Query Help

Sir,

We are try to insert query like this

Insert into Table_1 (smDate,Description) Values ('Thu, Feb 15, 2007 03:00 PM', ' Hai, It's Just for Testing')

This is Exact Query about this...

We know about MS ACCESS it has Built in function like Format('Thu, Feb 15, 2007 03:00 PM','mm/dd/yyyy HH:MM')

But I am new to SQL. I dont know the The Date Format built in function in SQL Server.

How can i Insert this Quesry to SQL Table

and also How can insert "it's " this type of words into SQL..

Can you help me

this is very helpful for my project

Thanks With Regards

S.Senthil Nathan

Senthil:

look up CAST AND CONVERT under CONVERT in books online to get a look at date and time formats. The ISO format is format 112. This should get you moving in the right direction.


Dave

|||Hi,

convertion was already explained by another posted, the issue with the quotes can be solved using two single quotes instead of one.

HTH, Jens K. Suessmeyer.

http://www.sqlserver2005.de

I need some help on my Sql string

Hi,

i have a sqlString to select records from database as below,


StrSql="Select Distinct ItemCode From StockOnHand Where " & _
"Description like @.Des"

this sql string works correctly, but i need to display those distinct ItemCode with their Description and Price, but i failed using the sql String at below...


StrSql="Select Distinct ItemCode, Description, Price From StockOnHand Where " & _
"Description like @.Des"

I know there is something wrong with my sql string.. but my SQL knowledge is onli at the basic level, can any1 pls help me on this...?

Thanks in advances
life's Ng::I know there is something wrong with my sql string..

Good, let's start VERY VERY VERY at the basics.

This:

::but i failed using the sql String at below...

will NOT get you help.

It did not "just fail", it gave you an error string DESCRIBING the error. Now, even while you may not understand this error string when you read it (and normally it is pretty self-explaining), WE may want to have a look at the EXACT error coming there.

So please, post the error you got, too.

Btw, using:

"Select DISTINCT" is about the best way to kill your peroformance anyhow. And - sorry - not really smart in the queries you give there. Unless, naturally, you want your database to be terribly slow.|||Without knowing the exact error, I can tell you that this is not correct:
"Description like @.Des"

try this instead:
"Description like '%@.Des%'"|||Hi, Sorry for my mistake to not descript my problem well and thanks for ur info bout "DISTINCT"

i dint receive any error with both of the SQL statements.

In my table, there is 10 columns ("Description", "ItemCode", "Prices".......)

the 2nd one return records which is not expected... few records selected with the same ItemCode, i onli want the distinct ItemCode displayed according to its description.

This page is created just for user to search&check on the ItemCode using their Description... I think i need to reconstruct my database design.

Best Regards
life's Ng