[SQL] Query with Parameters and Wildcards
I have a query that works on SQL Server to return customers that contain the string entered by the user by accepting parameters and using the LIKE keyword. I would like to move this to postgreSQL but I'm just not sure how to get it done. This is the query SELECT * FROM Customers WHERE FirstName LIKE @custfirst + '%'; This works great on SQL Server but not on postgreSQL. Any help would be appreciated. -- View this message in context: http://www.nabble.com/Query-with-Parameters-and-Wildcards-tp23248274p23248274.html Sent from the PostgreSQL - sql mailing list archive at Nabble.com. -- Sent via pgsql-sql mailing list ([email protected]) To make changes to your subscription: http://www.postgresql.org/mailpref/pgsql-sql
Re: [SQL] Query with Parameters and Wildcards
On Apr 26, 2009, at 7:21 PM, landsharkdaddy wrote: I have a query that works on SQL Server to return customers that contain the string entered by the user by accepting parameters and using the LIKE keyword. I would like to move this to postgreSQL but I'm just not sure how to get it done. This is the query SELECT * FROM Customers WHERE FirstName LIKE @custfirst + '%'; This works great on SQL Server but not on postgreSQL. Any help would be appreciated. Why didn't it work? Any error message), or no result? Are you expecting case-insensitivity (try ILIKE) regards, Ries van Twisk - Ries van Twisk tags: Freelance TYPO3 Glassfish JasperReports JasperETL Flex Blaze-DS WebORB PostgreSQL DB-Architect email: [email protected] web: http://www.rvantwisk.nl/ skype: callto://r.vantwisk Phone: +1-810-476-4196 SIP: +1-747-690-5133 -- Sent via pgsql-sql mailing list ([email protected]) To make changes to your subscription: http://www.postgresql.org/mailpref/pgsql-sql
Re: [SQL] Query with Parameters and Wildcards
On Sun, Apr 26, 2009 at 6:21 PM, landsharkdaddy wrote: > > I have a query that works on SQL Server to return customers that contain the > string entered by the user by accepting parameters and using the LIKE > keyword. I would like to move this to postgreSQL but I'm just not sure how > to get it done. This is the query > > SELECT * FROM Customers WHERE FirstName LIKE @custfirst + '%'; > > This works great on SQL Server but not on postgreSQL. Any help would be > appreciated. Have you tried: SELECT * FROM Customers WHERE FirstName LIKE 'custfirst%'; What does the @ do in sql server? -- Sent via pgsql-sql mailing list ([email protected]) To make changes to your subscription: http://www.postgresql.org/mailpref/pgsql-sql
Re: [SQL] Query with Parameters and Wildcards
I have not tried that but I will in the morning. The @ in SQL is used to indicate a parameter passed to the query. In PostgreSQL it seems that the : is the same as the @ in SQL Server. I tried something like: SELECT * FROM Customers WHERE FirstName LIKE :custfirst + '%'; And it told me that the + could not be used. Not sure the exact message but I will check again tomorrow and see what it was and post the results. Scott Marlowe-2 wrote: > > On Sun, Apr 26, 2009 at 6:21 PM, landsharkdaddy > wrote: >> >> I have a query that works on SQL Server to return customers that contain >> the >> string entered by the user by accepting parameters and using the LIKE >> keyword. I would like to move this to postgreSQL but I'm just not sure >> how >> to get it done. This is the query >> >> SELECT * FROM Customers WHERE FirstName LIKE @custfirst + '%'; >> >> This works great on SQL Server but not on postgreSQL. Any help would be >> appreciated. > > Have you tried: > > SELECT * FROM Customers WHERE FirstName LIKE 'custfirst%'; > > What does the @ do in sql server? > > -- > Sent via pgsql-sql mailing list ([email protected]) > To make changes to your subscription: > http://www.postgresql.org/mailpref/pgsql-sql > > -- View this message in context: http://www.nabble.com/Query-with-Parameters-and-Wildcards-tp23248274p23250153.html Sent from the PostgreSQL - sql mailing list archive at Nabble.com. -- Sent via pgsql-sql mailing list ([email protected]) To make changes to your subscription: http://www.postgresql.org/mailpref/pgsql-sql
