SQL update query syntax with inner join

The SET needs to come before the FROM\JOIN\WHERE portion of the query. UPDATE CE SET sJobNumber = AD.JobNumber FROM CostEntry CE INNER JOIN ActiveCostDetails As AD ON CE.lUniqueID = AD.UniqueID WHERE CE.SEmployeeCode=”002″ AND SubString(CostCentre, 1, 1) = sDepartmentCode AND substring(CostCentre, 3, 1) = sCategoryCode AND substring(CostCentre, 5, 2) = sOperationCode

SqlAlchemy and Flask, how to query many-to-many relationship

The semantic of the relationship doesn’t look right. I think it should be something like: class Restaurant(db.Model): … dishes = db.relationship(‘Dish’, secondary=restaurant_dish, backref=db.backref(‘restaurants’)) Then, to retrieve all the dishes for a restaurant, you can do: x = Dish.query.filter(Dish.restaurants.any(name=name)).all() This should generate a query like: SELECT dish.* FROM dish WHERE EXISTS ( SELECT 1 FROM restaurant_dish … Read more

get next sequence value from database using hibernate

You can use Hibernate Dialect API for Database independence as follow class SequenceValueGetter { private SessionFactory sessionFactory; // For Hibernate 3 public Long getId(final String sequenceName) { final List<Long> ids = new ArrayList<Long>(1); sessionFactory.getCurrentSession().doWork(new Work() { public void execute(Connection connection) throws SQLException { DialectResolver dialectResolver = new StandardDialectResolver(); Dialect dialect = dialectResolver.resolveDialect(connection.getMetaData()); PreparedStatement preparedStatement = … Read more

Determine ROW that caused “unexpected end of file” error in BULK INSERT?

To locate the troublesome row use the errorfile specifier. BULK INSERT myData FROM ‘C:\…\…\myData.csv’ WITH ( FIELDTERMINATOR = ‘,’, ROWTERMINATOR = ‘\n’, ERRORFILE = ‘C:\…\…\myRubbishData.log’ ); myRubbishData.log will have the offending rows and a companion file myRubbishData.log.txt will give you row numbers and offsets into the file. Companion file example: Row 3 File Offset 152 … Read more

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)